-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into inline-tool-adapter
- Loading branch information
Showing
12 changed files
with
214 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Finds nearest next carriage return symbol from passed position | ||
* | ||
* @param text - string to search in | ||
* @param position - search starting position | ||
*/ | ||
export function findNextHardLineBoundary(text: string, position: number): number { | ||
const nextLineBoundary = /\n/g; | ||
|
||
nextLineBoundary.lastIndex = position; | ||
|
||
const match = nextLineBoundary.exec(text); | ||
|
||
return match ? match.index : text.length; | ||
} | ||
|
||
/** | ||
* Finds nearest previous caret symbol before passed position | ||
* | ||
* @param text - sting to search in | ||
* @param position - search finish position | ||
*/ | ||
export function findPreviousHardLineBoundary(text: string, position: number): number { | ||
const previousLineBoundary = /\n/g; | ||
|
||
let match = previousLineBoundary.exec(text); | ||
|
||
while (match) { | ||
const newMatch = previousLineBoundary.exec(text); | ||
|
||
if (!newMatch || newMatch.index >= position) { | ||
break; | ||
} | ||
|
||
match = newMatch; | ||
} | ||
|
||
return match && match.index < position ? match.index : 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const APOSTROPHE_AND_CURLY_QUOTES = "['\u2018\u2019]"; | ||
const PUNCTUATION = '.,!?:;"\\(\\){}\\[\\]<>@*~\\/\\-#$&|^%+='; | ||
const WHITESPACE = '\\s'; | ||
|
||
const WHITESPACE_AND_PUNCTUATION = `[${WHITESPACE}${PUNCTUATION}]`; | ||
|
||
/** | ||
* Finds the nearest next word boundary from the passed position | ||
* | ||
* @param text - string to search in | ||
* @param position - search starting position | ||
*/ | ||
export function findNextWordBoundary(text: string, position: number): number { | ||
const nextWordBoundary = new RegExp( | ||
/** | ||
* Match whitespace or punctuation | ||
* or an apostrophe or curly quotes followed by a whitespace character or punctuation | ||
*/ | ||
`(${WHITESPACE_AND_PUNCTUATION}|${APOSTROPHE_AND_CURLY_QUOTES}(?=${WHITESPACE_AND_PUNCTUATION}))`, | ||
'g' | ||
); | ||
|
||
/** | ||
* Start searching from the next character to allow word deletion with one non-word character before the word | ||
*/ | ||
nextWordBoundary.lastIndex = position + 1; | ||
|
||
const match = nextWordBoundary.exec(text); | ||
|
||
return match ? match.index : text.length; | ||
} | ||
|
||
/** | ||
* Finds the nearest previous word boundary before the passed position | ||
* | ||
* @param text - string to search in | ||
* @param position - search finish position | ||
*/ | ||
export function findPreviousWordBoundary(text: string, position: number): number { | ||
const previousWordBoundary = new RegExp( | ||
/** | ||
* Match whitespace or punctuation, | ||
* or an apostrophe or curly quotes preceded by whitespace or punctuation | ||
*/ | ||
`(${WHITESPACE_AND_PUNCTUATION}|(?<=${WHITESPACE_AND_PUNCTUATION})${APOSTROPHE_AND_CURLY_QUOTES})`, | ||
'g' | ||
); | ||
|
||
let match = previousWordBoundary.exec(text); | ||
|
||
while (match) { | ||
const newMatch = previousWordBoundary.exec(text); | ||
|
||
if (!newMatch || newMatch.index >= position) { | ||
break; | ||
} | ||
|
||
match = newMatch; | ||
} | ||
|
||
return match && match.index < position ? match.index : 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.