Remove cyclic dependency
This commit is contained in:
Родитель
763553789a
Коммит
976fb67c32
14
src/query.ts
14
src/query.ts
|
@ -1,5 +1,3 @@
|
|||
import {Match} from './text-expander-element'
|
||||
|
||||
type Query = {
|
||||
text: string
|
||||
position: number
|
||||
|
@ -8,7 +6,7 @@ type Query = {
|
|||
type QueryOptions = {
|
||||
lookBackIndex: number
|
||||
multiWord: boolean
|
||||
previousMatch: Match | null
|
||||
lastMatchPosition: number | null
|
||||
}
|
||||
|
||||
const boundary = /\s|\(|\[/
|
||||
|
@ -18,10 +16,10 @@ export default function query(
|
|||
text: string,
|
||||
key: string,
|
||||
cursor: number,
|
||||
{multiWord, lookBackIndex, previousMatch}: QueryOptions = {
|
||||
{multiWord, lookBackIndex, lastMatchPosition}: QueryOptions = {
|
||||
multiWord: false,
|
||||
lookBackIndex: 0,
|
||||
previousMatch: null
|
||||
lastMatchPosition: null
|
||||
}
|
||||
): Query | void {
|
||||
// Activation key not found in front of the cursor.
|
||||
|
@ -32,13 +30,13 @@ export default function query(
|
|||
if (keyIndex < lookBackIndex) return
|
||||
|
||||
if (multiWord) {
|
||||
if (previousMatch) {
|
||||
keyIndex = previousMatch.position - 1
|
||||
if (lastMatchPosition !== null) {
|
||||
keyIndex = lastMatchPosition - 1
|
||||
}
|
||||
|
||||
// Space immediately after activation key followed by the cursor
|
||||
const charAfterKey = text[keyIndex + 1]
|
||||
if (charAfterKey === ' ' && cursor === keyIndex + 2) return
|
||||
if (charAfterKey === ' ' && cursor >= keyIndex + 2) return
|
||||
|
||||
// New line the cursor and previous activation key.
|
||||
const newLineIndex = text.lastIndexOf('\n', cursor - 1)
|
||||
|
|
|
@ -2,7 +2,7 @@ import Combobox from '@github/combobox-nav'
|
|||
import query from './query'
|
||||
import textFieldSelectionPosition from './text-field-selection-position'
|
||||
|
||||
export type Match = {
|
||||
type Match = {
|
||||
text: string
|
||||
key: string
|
||||
position: number
|
||||
|
@ -186,7 +186,7 @@ class TextExpander {
|
|||
const found = query(text, key, cursor, {
|
||||
multiWord,
|
||||
lookBackIndex: this.lookBackIndex,
|
||||
previousMatch: this.match
|
||||
lastMatchPosition: this.match ? this.match.position : null
|
||||
})
|
||||
if (found) {
|
||||
return {text: found.text, key, position: found.position}
|
||||
|
|
Загрузка…
Ссылка в новой задаче