mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Simplify check for when we are editing lines with metadata commands
This commit is contained in:
parent
c53ff0fa84
commit
f9c074a31e
1 changed files with 6 additions and 32 deletions
|
@ -18,41 +18,15 @@ define [
|
||||||
return
|
return
|
||||||
if change.action not in ['remove', 'insert']
|
if change.action not in ['remove', 'insert']
|
||||||
return
|
return
|
||||||
cursorPosition = @editor.getCursorPosition()
|
|
||||||
end = change.end
|
end = change.end
|
||||||
range = new Range(end.row, 0, end.row, end.column)
|
lineText = @editor.getSession().getLine end.row
|
||||||
lineUpToCursor = @editor.getSession().getTextRange range
|
|
||||||
if lineUpToCursor.trim() == '%' or lineUpToCursor.slice(0, 1) == '\\'
|
|
||||||
range = new Range(end.row, 0, end.row, end.column + 80)
|
|
||||||
lineUpToCursor = @editor.getSession().getTextRange range
|
|
||||||
commandFragment = getLastCommandFragment lineUpToCursor
|
|
||||||
|
|
||||||
linesContainPackage = _.any(
|
# Defensive check against extremely long lines
|
||||||
change.lines,
|
return if lineText.length > 10000
|
||||||
(line) -> line.match(/^\\usepackage(?:\[.{0,80}?])?{(.{0,80}?)}/)
|
|
||||||
)
|
|
||||||
linesContainReqPackage = _.any(
|
|
||||||
change.lines,
|
|
||||||
(line) -> line.match(/^\\RequirePackage(?:\[.{0,80}?])?{(.{0,80}?)}/)
|
|
||||||
)
|
|
||||||
linesContainLabel = _.any(
|
|
||||||
change.lines,
|
|
||||||
(line) -> line.match(/\\label{(.{0,80}?)}/)
|
|
||||||
)
|
|
||||||
linesContainMeta =
|
|
||||||
linesContainPackage or
|
|
||||||
linesContainLabel or
|
|
||||||
linesContainReqPackage
|
|
||||||
|
|
||||||
lastCommandFragmentIsLabel = commandFragment?.slice(0, 7) == '\\label{'
|
# Check if edited line contains metadata commands
|
||||||
lastCommandFragmentIsPackage = commandFragment?.slice(0, 11) == '\\usepackage'
|
if /\\(usepackage|RequirePackage|label)(\[.*])?({.*})?/.test(lineText)
|
||||||
lastCommandFragmentIsReqPack = commandFragment?.slice(0, 15) == '\\RequirePackage'
|
|
||||||
lastCommandFragmentIsMeta =
|
|
||||||
lastCommandFragmentIsPackage or
|
|
||||||
lastCommandFragmentIsLabel or
|
|
||||||
lastCommandFragmentIsReqPack
|
|
||||||
|
|
||||||
if linesContainMeta or lastCommandFragmentIsMeta
|
|
||||||
@scheduleLoadCurrentDocMetaFromServer()
|
@scheduleLoadCurrentDocMetaFromServer()
|
||||||
|
|
||||||
@editor.on "changeSession", (e) =>
|
@editor.on "changeSession", (e) =>
|
||||||
|
|
Loading…
Reference in a new issue