Skip to content

Commit

Permalink
Merge pull request #5165 from ajaxorg/snippets-no-multi-cursor
Browse files Browse the repository at this point in the history
fix error when attempting to insert snippet without MultiSelect
  • Loading branch information
nightwing authored May 12, 2023
2 parents 3f29428 + 85a7da8 commit e30622d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 17 deletions.
27 changes: 25 additions & 2 deletions src/editor_commands_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ var MockRenderer = require("./test/mockrenderer").MockRenderer;
var JavaScriptMode = require("./mode/javascript").Mode;
var HTMLMode = require("./mode/html").Mode;
var assert = require("./test/assertions");

require("./multi_select");

var editor;

var exec = function(name, times, args) {
Expand All @@ -31,15 +34,35 @@ module.exports = {
setTimeout(function() {
assert.equal(editor.$highlightPending, false);
assert.ok(editor.session.$bracketHighlight);
assert.equal(
editor.session.$bracketHighlight.ranges + "",
"Range: [0/1] -> [0/5],Range: [0/26] -> [0/30]"
);
exec("gotoend", 1);
exec("gotoleft", 3);
assert.equal(editor.$highlightPending, true);
setTimeout(function() {
assert.equal(editor.$highlightPending, false);
done();

editor.setValue("{}");
exec("gotostart", 1);
setTimeout(function() {
assert.equal(
editor.session.$bracketHighlight.ranges + "",
'Range: [0/0] -> [0/2]'
);
exec("gotoend", 1);
setTimeout(function() {
assert.equal(
editor.session.$bracketHighlight.ranges + "",
'Range: [0/0] -> [0/2]'
);
done();
}, 51);
}, 51);
}, 51);
}, 51);
},
},
"test modifyNumber": function() {
editor = new Editor(new MockRenderer());
editor.setValue("999");
Expand Down
2 changes: 0 additions & 2 deletions src/multi_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,10 +917,8 @@ require("./config").defineOptions(Editor.prototype, "editor", {
set: function(val) {
MultiSelect(this);
if (val) {
this.on("changeSession", this.$multiselectOnSessionChange);
this.on("mousedown", onMouseDown);
} else {
this.off("changeSession", this.$multiselectOnSessionChange);
this.off("mousedown", onMouseDown);
}
},
Expand Down
12 changes: 12 additions & 0 deletions src/snippets_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if (typeof process !== "undefined") {

"use strict";
var Editor = require("./editor").Editor;
var EditSession = require("./edit_session").EditSession;
var MockRenderer = require("./test/mockrenderer").MockRenderer;
var JavascriptMode = require("./mode/javascript").Mode;
require("./multi_select");
Expand Down Expand Up @@ -358,6 +359,17 @@ module.exports = {
snippetManager.insertSnippet(this.editor, "def multiply_with_random(array):\n\t", options);
snippetManager.insertSnippet(this.editor, "for i in range(len(array)):\n\t\tarray[i] *= random.randint(1, 10)\n\treturn array", options);
assert.equal(editor.getValue(), correctlyFormattedCode);
},

"test: snippets without multiselct": function() {
var session = new EditSession([]);
var editor = new Editor(new MockRenderer());
editor.setOption("enableMultiselect", false);
editor.setSession(session);

editor.insertSnippet("hello $1 world $1");
editor.onTextInput("!");
assert.equal(editor.getValue(), "hello ! world !");
}
};

Expand Down
29 changes: 16 additions & 13 deletions src/test/all_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var mockdom = require("../test/mockdom");
var AsyncTest = require("asyncjs").test;
var async = require("asyncjs");

var useMockdom = location.search.indexOf("mock=1") != -1;

var passed = 0;
var failed = 0;
var log = document.getElementById("log");
Expand Down Expand Up @@ -43,13 +45,10 @@ var testNames = [
"ace/keyboard/gutter_handler_test",
"ace/layer/text_test",
"ace/lib/event_emitter_test",
"ace/mode/coffee/parser_test",
"ace/mode/coldfusion_test",
"ace/mode/css_test",
"ace/mode/css_worker",
"ace/mode/html_test",
"ace/mode/javascript_test",
"ace/mode/javascript_worker_test",
"ace/mode/logiql_test",
"ace/mode/python_test",
"ace/mode/text_test",
Expand Down Expand Up @@ -77,14 +76,16 @@ var testNames = [
"ace/tokenizer_test",
"ace/test/mockdom_test",
"ace/undomanager_test",
"ace/virtual_renderer_test",
"ace/mode/yaml_worker_test"
"ace/virtual_renderer_test"
];

var html = ["<a href='?'>all tests</a><br>"];
var html = [
"<a href='?mock=1'>use mockdom</a><br>",
"<a href='?runall'>Run all tests</a><br>"
];
for (var i in testNames) {
var href = testNames[i];
html.push("<a href='?", href, "'>", href.replace(/^ace\//, "") ,"</a><br>");
html.push("<a href='?", href, (useMockdom ? "&mock=1" : ""), "'>", href.replace(/^ace\//, "") ,"</a><br>");
}

var nav = el("div");
Expand All @@ -110,21 +111,23 @@ if (location.search.indexOf("show=1") != -1) {
});
}

if (location.search.indexOf("mock=1") != -1) {
if (useMockdom) {
mockdom.loadInBrowser(window);
}


var selectedTests = [];
if (location.search) {
var parts = location.search.split(/[&?]|\w+=\w+/).filter(Boolean);
if (parts[0])
testNames = parts[0].split(",");
if (parts[0] == "runall")
selectedTests = testNames;
else
selectedTests = parts[0].split(",");
}
var filter = location.hash.substr(1);
window.onhashchange = function() { location.reload(); };

require(testNames, function() {
var tests = testNames.map(function(x) {
require(selectedTests, function() {
var tests = selectedTests.map(function(x) {
var module = require(x);
module.href = x;
return module;
Expand Down

0 comments on commit e30622d

Please sign in to comment.