mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Experimental handling of completion for existing commands
This commit is contained in:
parent
127d5ded86
commit
415de9e2ec
1 changed files with 27 additions and 5 deletions
|
@ -161,16 +161,38 @@ define [
|
||||||
data = popup.getData(popup.getRow())
|
data = popup.getData(popup.getRow())
|
||||||
data.completer =
|
data.completer =
|
||||||
insertMatch: (editor, matchData) ->
|
insertMatch: (editor, matchData) ->
|
||||||
console.log ">> custom insertMatch"
|
|
||||||
ranges = editor.selection.getAllRanges()
|
ranges = editor.selection.getAllRanges()
|
||||||
for range in ranges
|
for range in ranges
|
||||||
range.start.column -= completions.filterText.length;
|
left = _.clone(range)
|
||||||
editor.session.remove(range);
|
right = _.clone(range)
|
||||||
|
left.start.column -= completions.filterText.length;
|
||||||
|
editor.session.remove(left);
|
||||||
|
beyondCursorRange = new Range(
|
||||||
|
right.start.row,
|
||||||
|
right.start.column,
|
||||||
|
right.end.row,
|
||||||
|
99999
|
||||||
|
)
|
||||||
|
lineBeyondCursor = editor.getSession().getTextRange(beyondCursorRange)
|
||||||
|
if lineBeyondCursor
|
||||||
|
if partialCommandMatch = lineBeyondCursor.match(/^([a-z0-9]+)\{/)
|
||||||
|
# We've got a partial command after the cursor
|
||||||
|
commandTail = partialCommandMatch[1]
|
||||||
|
# remove rest of the partial command
|
||||||
|
right.end.column += commandTail.length - completions.filterText.length
|
||||||
|
editor.session.remove(right);
|
||||||
|
# trim the completion text to just the command, without braces
|
||||||
|
# example: '\cite{}' -> '\cite'
|
||||||
|
if matchData.snippet
|
||||||
|
matchData.snippet = matchData.snippet.replace(/[{\[].*[}\]]/, '')
|
||||||
|
if matchData.caption
|
||||||
|
matchData.caption = matchData.caption.replace(/[{\[].*[}\]]/, '')
|
||||||
|
if matchData.value
|
||||||
|
matchData.value = matchData.value.replace(/[{\[].*[}\]]/, '')
|
||||||
|
# finally, insert the match
|
||||||
if matchData.snippet
|
if matchData.snippet
|
||||||
console.log ">> snippet"
|
|
||||||
aceSnippetManager.insertSnippet(editor, matchData.snippet);
|
aceSnippetManager.insertSnippet(editor, matchData.snippet);
|
||||||
else
|
else
|
||||||
console.log ">> string", matchData
|
|
||||||
editor.execCommand("insertstring", matchData.value || matchData);
|
editor.execCommand("insertstring", matchData.value || matchData);
|
||||||
|
|
||||||
Autocomplete::_insertMatch.call this, data
|
Autocomplete::_insertMatch.call this, data
|
||||||
|
|
Loading…
Reference in a new issue