Skip to content

Commit

Permalink
off by one errors are fun!
Browse files Browse the repository at this point in the history
  • Loading branch information
SatsAllDay committed Oct 4, 2023
1 parent 10ab192 commit 48961a6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions components/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,23 +155,23 @@ export function MarkdownInput ({ label, topLevel, groupClassName, onChange, setH
setHasImgLink(mdHas(e.target.value, ['link', 'image']))
}
// check for at-mention editing
const { value } = e.target
const { value, selectionStart } = e.target
let priorSpace = -1
for (let i = e.target.selectionStart; i >= 0; i--) {
for (let i = selectionStart - 1; i >= 0; i--) {
if ([' ', '\n'].includes(value[i])) {
priorSpace = i
break
}
}
let nextSpace = value.length
for (let i = e.target.selectionStart; i <= value.length; i++) {
for (let i = selectionStart; i <= value.length; i++) {
if ([' ', '\n'].includes(value[i])) {
nextSpace = i
break
}
}
const currentSequence = value.substring(priorSpace + 1, nextSpace)
console.log({ currentSequence })
// console.log({ value, selectionStart, priorSpace, nextSpace, currentSequence })

// currently typing an at-mention, let's query for matching users
setAtMentionQuery(currentSequence)
Expand Down

0 comments on commit 48961a6

Please sign in to comment.