mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #668 from sharelatex/revert-663-as-simplify-metadata-check
Revert "Simplify package metadata check"
This commit is contained in:
commit
5121257f14
1 changed files with 32 additions and 6 deletions
|
@ -18,15 +18,41 @@ define [
|
|||
return
|
||||
if change.action not in ['remove', 'insert']
|
||||
return
|
||||
|
||||
cursorPosition = @editor.getCursorPosition()
|
||||
end = change.end
|
||||
lineText = @editor.getSession().getLine end.row
|
||||
range = new Range(end.row, 0, end.row, end.column)
|
||||
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
|
||||
|
||||
# Defensive check against extremely long lines
|
||||
return if lineText.length > 10000
|
||||
linesContainPackage = _.any(
|
||||
change.lines,
|
||||
(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
|
||||
|
||||
# Check if edited line contains metadata commands
|
||||
if /\\(usepackage|RequirePackage|label)(\[.*])?({.*})?/.test(lineText)
|
||||
lastCommandFragmentIsLabel = commandFragment?.slice(0, 7) == '\\label{'
|
||||
lastCommandFragmentIsPackage = commandFragment?.slice(0, 11) == '\\usepackage'
|
||||
lastCommandFragmentIsReqPack = commandFragment?.slice(0, 15) == '\\RequirePackage'
|
||||
lastCommandFragmentIsMeta =
|
||||
lastCommandFragmentIsPackage or
|
||||
lastCommandFragmentIsLabel or
|
||||
lastCommandFragmentIsReqPack
|
||||
|
||||
if linesContainMeta or lastCommandFragmentIsMeta
|
||||
@scheduleLoadCurrentDocMetaFromServer()
|
||||
|
||||
@editor.on "changeSession", (e) =>
|
||||
|
|
Loading…
Reference in a new issue