mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-01 23:42:28 +00:00
More robust change detection for autocomplete.
- accurately detect when labels are involved in 'remove' event
This commit is contained in:
parent
1ba8b702ad
commit
ea9a0dda83
1 changed files with 23 additions and 17 deletions
|
@ -121,27 +121,33 @@ define [
|
||||||
onChange: (change) ->
|
onChange: (change) ->
|
||||||
cursorPosition = @editor.getCursorPosition()
|
cursorPosition = @editor.getCursorPosition()
|
||||||
end = change.end
|
end = change.end
|
||||||
|
range = new Range(end.row, 0, end.row, end.column)
|
||||||
|
lineUpToCursor = @editor.getSession().getTextRange(range)
|
||||||
|
commandFragment = getLastCommandFragment(lineUpToCursor)
|
||||||
|
|
||||||
|
# Check if user has backspaced/deleted a highlighted region of text
|
||||||
|
# and see if that contains a `\label{}`
|
||||||
|
if change.action == 'remove'
|
||||||
|
if _.any(change.lines, (line) -> line.match(/\\label\{[^\}\n\\]{0,80}\}/))
|
||||||
|
@labelsManager.scheduleLoadLabelsFromOpenDoc()
|
||||||
|
if commandFragment? and commandFragment.length > 2
|
||||||
|
if commandFragment.startsWith('\\label{')
|
||||||
|
@labelsManager.scheduleLoadLabelsFromOpenDoc()
|
||||||
|
|
||||||
# Check that this change was made by us, not a collaborator
|
# Check that this change was made by us, not a collaborator
|
||||||
# (Cursor is still one place behind)
|
# (Cursor is still one place behind)
|
||||||
# NOTE: this is also the case when a user backspaces over a highlighted region
|
# NOTE: this is also the case when a user backspaces over a highlighted region
|
||||||
if end.row == cursorPosition.row and end.column == cursorPosition.column + 1
|
if (
|
||||||
if change.action == "insert"
|
change.action == "insert" and
|
||||||
range = new Range(end.row, 0, end.row, end.column)
|
end.row == cursorPosition.row and
|
||||||
lineUpToCursor = @editor.getSession().getTextRange(range)
|
end.column == cursorPosition.column + 1
|
||||||
commandFragment = getLastCommandFragment(lineUpToCursor)
|
)
|
||||||
|
if commandFragment? and commandFragment.length > 2
|
||||||
if commandFragment? and commandFragment.length > 2
|
if commandFragment.startsWith('\\label{')
|
||||||
if commandFragment.startsWith('\\label{')
|
|
||||||
@labelsManager.scheduleLoadLabelsFromOpenDoc()
|
|
||||||
setTimeout () =>
|
|
||||||
@editor.execCommand("startAutocomplete")
|
|
||||||
, 0
|
|
||||||
else
|
|
||||||
# Check if user has backspaced/deleted a highlighted region of text
|
|
||||||
# and see if that contains a `\label{}`
|
|
||||||
if change.action == 'remove'
|
|
||||||
if _.any(change.lines, (line) -> line.match(/\\label{.*}/))
|
|
||||||
@labelsManager.scheduleLoadLabelsFromOpenDoc()
|
@labelsManager.scheduleLoadLabelsFromOpenDoc()
|
||||||
|
setTimeout () =>
|
||||||
|
@editor.execCommand("startAutocomplete")
|
||||||
|
, 0
|
||||||
|
|
||||||
monkeyPatchAutocomplete: () ->
|
monkeyPatchAutocomplete: () ->
|
||||||
Autocomplete = ace.require("ace/autocomplete").Autocomplete
|
Autocomplete = ace.require("ace/autocomplete").Autocomplete
|
||||||
|
|
Loading…
Reference in a new issue