Skip to content

Commit

Permalink
fix: Fix bug with missing token in latex folding (#5093)
Browse files Browse the repository at this point in the history
* fix bug with missing token

* add test for latex folding

Issue #5090
  • Loading branch information
mkslanc authored Mar 16, 2023
1 parent a981972 commit 44b3a3e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mode/folding/latex.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ oop.inherits(FoldMode, BaseFoldMode);

var getType = function() {
var token = stream.stepForward();
var type = token.type == "lparen" ?stream.stepForward().value : "";
var type = token && token.type == "lparen" ? stream.stepForward().value : "";
if (dir === -1) {
stream.stepBackward();
if (type)
Expand Down
31 changes: 31 additions & 0 deletions src/mode/folding/latex_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
if (typeof process !== "undefined") require("amd-loader");

"use strict";

var LatexMode = require("../latex").Mode;
var EditSession = require("../../edit_session").EditSession;
var assert = require("../../test/assertions");

module.exports = {
"test: latex block folding": function () {
var session = new EditSession([
'\\usepackage{amsmath}', '\\title{\\LaTeX}', '\\date{}', '\\begin'
]);

var mode = new LatexMode();
session.setFoldStyle("markbegin");
session.setMode(mode);

assert.equal(session.getFoldWidget(0), "");
assert.equal(session.getFoldWidget(1), "");
assert.equal(session.getFoldWidget(2), "");
assert.equal(session.getFoldWidget(3), "start");
assert.equal(session.getFoldWidgetRange(3), null);

session.setValue(session.getValue() + '{test}\nsome text here \n\\end{test}');

assert.range(session.getFoldWidgetRange(3), 3, 12, 5, 0);
}
};

if (typeof module !== "undefined" && module === require.main) require("asyncjs").test.testcase(module.exports).exec();

0 comments on commit 44b3a3e

Please sign in to comment.