Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions lib/current-word.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
function getCurrentWord(text, index, initialIndex) {
if (text[index] === " " || text[index] === undefined) return ""
if (index < initialIndex) {
return getCurrentWord(text, index - 1, initialIndex) + text[index]
}
if (index > initialIndex) {
return text[index] + getCurrentWord(text, index + 1, initialIndex)
}
return getCurrentWord(text, index - 1, initialIndex) + text[index] + getCurrentWord(text, index + 1, initialIndex)
function getCurrentWord(text, index, trigger) {
const startIndex = text.lastIndexOf(trigger, index + 1)
return text.substring(startIndex, index + 1)
}

export default getCurrentWord
12 changes: 6 additions & 6 deletions lib/suggestion-portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ class SuggestionPortal extends React.Component {
}

matchCapture = () => {
const { state, capture } = this.props
const { state, capture, trigger } = this.props

if (!state.selection.anchorKey) return ''

const { anchorText, anchorOffset } = state

const currentWord = getCurrentWord(anchorText.text, anchorOffset - 1, anchorOffset - 1)
const currentWord = getCurrentWord(anchorText.text, anchorOffset - 1, trigger)

const text = this.getMatchText(currentWord, capture)

Expand All @@ -126,21 +126,21 @@ class SuggestionPortal extends React.Component {
getMatchText = (text, trigger) => {
const matchArr = text.match(trigger)

if (matchArr) {
if (matchArr && matchArr[0].length === text.length) {
return matchArr[1].toLowerCase()
}

return undefined
}

getFilteredSuggestions = () => {
const { suggestions, state, capture, resultSize } = this.props
const { suggestions, state, capture, resultSize, trigger } = this.props

if (!state.selection.anchorKey) return []

const { anchorText, anchorOffset } = state

const currentWord = getCurrentWord(anchorText.text, anchorOffset - 1, anchorOffset - 1)
const currentWord = getCurrentWord(anchorText.text, anchorOffset - 1, trigger)

const text = this.getMatchText(currentWord, capture)

Expand All @@ -157,7 +157,7 @@ class SuggestionPortal extends React.Component {
const { menu } = this.state
if (!menu) return

const match = this.matchCapture();
const match = this.matchCapture()
if (match === undefined) {
menu.removeAttribute('style')
return
Expand Down