Skip to content

Commit

Permalink
Merge pull request ajaxorg#2936 from ajaxorg/fix/various
Browse files Browse the repository at this point in the history
Fix several small issues
  • Loading branch information
lennartcl committed Apr 6, 2016
2 parents 2d4b2f6 + 79e5e20 commit edd676b
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 70 deletions.
51 changes: 50 additions & 1 deletion demo/kitchen-sink/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,4 +582,53 @@ env.editor.setOptions({
var beautify = require("ace/ext/beautify");
env.editor.commands.addCommands(beautify.commands);

});

// global keybindings

var KeyBinding = require("ace/keyboard/keybinding").KeyBinding;
var CommandManager = require("ace/commands/command_manager").CommandManager;
var commandManager = new CommandManager();
var kb = new KeyBinding({
commands: commandManager,
fake: true
});
event.addCommandKeyListener(document.documentElement, kb.onCommandKey.bind(kb));
event.addListener(document.documentElement, "keyup", function(e) {
if (e.keyCode === 18) // do not trigger browser menu on windows
e.preventDefault();
});
commandManager.addCommands([{
name: "window-left",
bindKey: {win: "cmd-alt-left", mac: "ctrl-cmd-left"},
exec: function() {
moveFocus("left");
}
}, {
name: "window-right",
bindKey: {win: "cmd-alt-right", mac: "ctrl-cmd-right"},
exec: function() {
moveFocus("right");
}
}, {
name: "window-up",
bindKey: {win: "cmd-alt-up", mac: "ctrl-cmd-up"},
exec: function() {
moveFocus("up");
}
}, {
name: "window-down",
bindKey: {win: "cmd-alt-down", mac: "ctrl-cmd-down"},
exec: function() {
moveFocus("down");
}
}]);

function moveFocus() {
var el = document.activeElement;
if (el == env.editor.textInput.getElement())
env.editor.cmdLine.focus();
else
env.editor.focus();
}

});
3 changes: 3 additions & 0 deletions demo/kitchen-sink/docs/tsx.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var mode = <div>
Typescript + <b> JSX </b>
</div>;
1 change: 1 addition & 0 deletions lib/ace/ext/modelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ var supportedModes = {
Toml: ["toml"],
Twig: ["twig|swig"],
Typescript: ["ts|typescript|str"],
TSX: ["tsx"],
Vala: ["vala"],
VBScript: ["vbs|vb"],
Velocity: ["vm"],
Expand Down
2 changes: 1 addition & 1 deletion lib/ace/keyboard/keybinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ var KeyBinding = function(editor) {
success = commands.exec("insertstring", this.$editor, keyString);
}

if (success)
if (success && this.$editor._signal)
this.$editor._signal("keyboardActivity", toExecute);

return success;
Expand Down
31 changes: 4 additions & 27 deletions lib/ace/lib/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function normalizeCommandKeys(callback, e, keyCode) {
var hashId = getModifierHash(e);

if (!useragent.isMac && pressedKeys) {
if (pressedKeys.OSKey)
if (e.getModifierState && (e.getModifierState("OS") || e.getModifierState("Win")))
hashId |= 8;
if (pressedKeys.altGr) {
if ((3 & hashId) != 3)
Expand Down Expand Up @@ -339,19 +339,8 @@ exports.addCommandKeyListener = function(el, callback) {
var lastDefaultPrevented = null;

addListener(el, "keydown", function(e) {
var keyCode = e.keyCode;
pressedKeys[keyCode] = (pressedKeys[keyCode] || 0) + 1;
if (keyCode == 91 || keyCode == 92) {
pressedKeys.OSKey = true;
} else if (pressedKeys.OSKey) {
if (e.timeStamp - pressedKeys.lastT > 200 && pressedKeys.count == 1)
resetPressedKeys();
}
if (pressedKeys[keyCode] == 1)
pressedKeys.count++;
// console.log(e.timeStamp - pressedKeys.lastT)
pressedKeys.lastT = e.timeStamp;
var result = normalizeCommandKeys(callback, e, keyCode);
pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1;
var result = normalizeCommandKeys(callback, e, e.keyCode);
lastDefaultPrevented = e.defaultPrevented;
return result;
});
Expand All @@ -364,17 +353,7 @@ exports.addCommandKeyListener = function(el, callback) {
});

addListener(el, "keyup", function(e) {
var keyCode = e.keyCode;
if (!pressedKeys[keyCode]) {
// console.log("resetting", 1)
resetPressedKeys();
} else {
pressedKeys.count = Math.max(pressedKeys.count - 1, 0);
}
if (keyCode == 91 || keyCode == 92) {
pressedKeys.OSKey = false;
}
pressedKeys[keyCode] = null;
pressedKeys[e.keyCode] = null;
});

if (!pressedKeys) {
Expand All @@ -386,8 +365,6 @@ exports.addCommandKeyListener = function(el, callback) {
function resetPressedKeys() {
// console.log("resetting")
pressedKeys = Object.create(null);
pressedKeys.count = 0;
pressedKeys.lastT = 0;
}

if (typeof window == "object" && window.postMessage && !useragent.isOldIE) {
Expand Down
10 changes: 9 additions & 1 deletion lib/ace/mode/behaviour/behaviour_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,22 @@ module.exports = {
" <SelfClosingTag />"
].join("\n"));
editor.session.setMode(new XMLMode);
exec("gotolinedown", 1);
exec("golinedown", 1);
exec("gotolineend", 1);
exec("insertstring", 1, '\n');
assert.equal(editor.session.getLine(2), " ");
exec("gotolineup", 1);
exec("gotolineend", 1);
exec("insertstring", 1, '\n');
assert.equal(editor.session.getLine(2), " ");
editor.session.setValue(["<OuterTag",
" <xyzrt"
].join("\n"));
exec("golinedown", 1);
exec("gotolineend", 1);
exec("selectleft", 3);
exec("insertstring", 1, '>');
assert.equal(editor.session.getLine(1), " <xy></xy>");
}
};

Expand Down
2 changes: 2 additions & 0 deletions lib/ace/mode/behaviour/cstyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ var CstyleBehaviour = function() {

this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
if (text == '"' || text == "'") {
if (this.lineCommentStart && this.lineCommentStart.indexOf(text) != -1)
return;
initContext(editor);
var quote = text;
var selection = editor.getSelectionRange();
Expand Down
6 changes: 5 additions & 1 deletion lib/ace/mode/behaviour/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var XmlBehaviour = function () {

this.add("autoclosing", "insertion", function (state, action, editor, session, text) {
if (text == '>') {
var position = editor.getCursorPosition();
var position = editor.getSelectionRange().start;
var iterator = new TokenIterator(session, position.row, position.column);
var token = iterator.getCurrentToken() || iterator.stepBackward();

Expand All @@ -124,6 +124,10 @@ var XmlBehaviour = function () {
// find tag name
while (!is(token, "tag-name")) {
token = iterator.stepBackward();
if (token.value == "<") {
token = iterator.stepForward();
break;
}
}

var tokenRow = iterator.getCurrentTokenRow();
Expand Down
8 changes: 4 additions & 4 deletions lib/ace/mode/drools_highlight_rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ var DroolsHighlightRules = function() {
[{
// variable :
token : ["variable.other","text","text"],
regex : "(" + identifierRe + ")(\\s*)(:)",
regex : "(" + identifierRe + ")(\\s*)(:)"
}, {
// query ...
token : ["keyword","text"],
Expand All @@ -211,15 +211,15 @@ var DroolsHighlightRules = function() {
}, {
// when ...
token : ["keyword","text"],
regex : "(when)(\\s*)",
regex : "(when)(\\s*)"
}, {
// then <java/mvel code> end
token : ["keyword","text"],
regex : "(then)(\\s*)",
next : "java-start"
}, {
token : "paren.lparen",
regex : /[\[({]/,
regex : /[\[({]/
}, {
token : "paren.rparen",
regex : /[\])}]/
Expand Down Expand Up @@ -247,7 +247,7 @@ var DroolsHighlightRules = function() {
this.embedRules(JavaHighlightRules, "java-", [
{
token : "support.function",
regex: "\\b(insert|modify|retract|update)\\b",
regex: "\\b(insert|modify|retract|update)\\b"
}, {
token : "keyword",
regex: "\\bend\\b",
Expand Down
60 changes: 30 additions & 30 deletions lib/ace/mode/folding/drools.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,38 @@ oop.inherits(FoldMode, BaseFoldMode);

(function() {

// regular expressions that identify starting and stopping points
this.foldingStartMarker = /(rule|declare|query|when|then)/;
this.foldingStopMarker = /end/;

this.getFoldWidgetRange = function(session, foldStyle, row) {
var line = session.getLine(row);
console.log(line);
var match = line.match(this.foldingStartMarker);
if (match) {
var i = match.index;

if (match[1]) {
var position = {row: row, column: line.length};
var iterator = new TokenIterator(session, position.row, position.column);
var seek = "end";
var token = iterator.getCurrentToken();
if (token.value == "when") {
seek = "then";
}
while(token) {
if (token.value == seek) {
return Range.fromPoints(position
,{row: iterator.getCurrentTokenRow(),
column: iterator.getCurrentTokenColumn()});
// regular expressions that identify starting and stopping points
this.foldingStartMarker = /\b(rule|declare|query|when|then)\b/;
this.foldingStopMarker = /\bend\b/;

this.getFoldWidgetRange = function(session, foldStyle, row) {
var line = session.getLine(row);
var match = line.match(this.foldingStartMarker);
if (match) {
var i = match.index;

if (match[1]) {
var position = {row: row, column: line.length};
var iterator = new TokenIterator(session, position.row, position.column);
var seek = "end";
var token = iterator.getCurrentToken();
if (token.value == "when") {
seek = "then";
}
while (token) {
if (token.value == seek) {
return Range.fromPoints(position ,{
row: iterator.getCurrentTokenRow(),
column: iterator.getCurrentTokenColumn()
});
}
token = iterator.stepForward();
}
}
token = iterator.stepForward();
}
}

}
// test each line, and return a range of segments to collapse
}
}
// test each line, and return a range of segments to collapse
}

}).call(FoldMode.prototype);

Expand Down
2 changes: 0 additions & 2 deletions lib/ace/mode/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ var Mode = function() {
HtmlMode.call(this);
this.HighlightRules = HandlebarsHighlightRules;
this.$behaviour = new HtmlBehaviour();

this.foldingRules = new HtmlFoldMode();
};

oop.inherits(Mode, HtmlMode);
Expand Down
6 changes: 3 additions & 3 deletions lib/ace/mode/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ define(function(require, exports, module) {

var Tokenizer = require("../tokenizer").Tokenizer;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var Behaviour = require("./behaviour").Behaviour;
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
var unicode = require("../unicode");
var lang = require("../lib/lang");
var TokenIterator = require("../token_iterator").TokenIterator;
var Range = require("../range").Range;

var Mode = function() {
this.HighlightRules = TextHighlightRules;
this.$behaviour = new Behaviour();
};

(function() {
this.$behaviour = new CstyleBehaviour();

this.tokenRe = new RegExp("^["
+ unicode.packages.L
Expand All @@ -62,7 +62,7 @@ var Mode = function() {

this.getTokenizer = function() {
if (!this.$tokenizer) {
this.$highlightRules = this.$highlightRules || new this.HighlightRules();
this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig);
this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
}
return this.$tokenizer;
Expand Down
52 changes: 52 additions & 0 deletions lib/ace/mode/tsx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2012, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */

/*
THIS FILE WAS AUTOGENERATED BY mode.tmpl.js
*/

define(function(require, exports, module) {
"use strict";

var oop = require("../lib/oop");
var tsMode = require("./typescript").Mode;

var Mode = function() {
tsMode.call(this);
this.$highlightRuleConfig = {jsx: true};
};
oop.inherits(Mode, tsMode);

(function() {
this.$id = "ace/mode/tsx";
}).call(Mode.prototype);

exports.Mode = Mode;
});

0 comments on commit edd676b

Please sign in to comment.