From ab50850be6684de0baaadbf84c2dd5ed40e0c95d Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 22 Apr 2012 14:58:42 +0400 Subject: [PATCH] add stupid semicolons; --- lib/ace/keyboard/vim/commands.js | 29 ++-- lib/ace/keyboard/vim/keyboard.js | 14 +- lib/ace/keyboard/vim/maps/motions.js | 190 +++++++++++++-------------- 3 files changed, 112 insertions(+), 121 deletions(-) diff --git a/lib/ace/keyboard/vim/commands.js b/lib/ace/keyboard/vim/commands.js index 77a30ac6..ca1cf54f 100644 --- a/lib/ace/keyboard/vim/commands.js +++ b/lib/ace/keyboard/vim/commands.js @@ -39,22 +39,15 @@ var repeat = function repeat(fn, count, args) { fn.apply(this, args); }; -var toggleCase = function toggleCase(ch) { - if (ch.toUpperCase() === ch) - return ch.toLowerCase(); - else - return ch.toUpperCase(); -}; - var ensureScrollMargin = function(editor) { - var renderer = editor.renderer + var renderer = editor.renderer; var pos = renderer.$cursorLayer.getPixelPosition(); var top = pos.top; var margin = HMARGIN * renderer.layerConfig.lineHeight; if (2 * margin > renderer.$size.scrollerHeight) - margin = renderer.$size.scrollerHeight / 2 + margin = renderer.$size.scrollerHeight / 2; if (renderer.scrollTop > top - margin) { renderer.session.setScrollTop(top - margin); @@ -102,11 +95,11 @@ var actions = { repeat(function() { var range = editor.selection.getRange(); if (range.isEmpty()) - range.end.column++ - var text = editor.session.getTextRange(range) - var toggled = text.toUpperCase() + range.end.column++; + var text = editor.session.getTextRange(range); + var toggled = text.toUpperCase(); if (toggled == text) - editor.navigateRight() + editor.navigateRight(); else editor.session.replace(range, toggled); }, count || 1); @@ -142,7 +135,7 @@ var actions = { ensureScrollMargin(editor); var r = editor.selection.getRange(); r.end.row = r.start.row; - r.end.column = r.start.column + r.end.column = r.start.column; editor.selection.setSelectionRange(r, true); } }, @@ -155,7 +148,7 @@ var actions = { ensureScrollMargin(editor); var r = editor.selection.getRange(); r.end.row = r.start.row; - r.end.column = r.start.column + r.end.column = r.start.column; editor.selection.setSelectionRange(r, true); } }, @@ -225,7 +218,7 @@ var actions = { }, "J": { fn: function(editor, range, count, param) { - var session = editor.session + var session = editor.session; range = editor.getSelectionRange(); var pos = {row: range.start.row, column: range.start.column}; count = count || range.end.row - range.start.row; @@ -235,7 +228,7 @@ var actions = { range.end.column = session.getLine(maxRow).length; range.end.row = maxRow; - var text = "" + var text = ""; for (var i = pos.row; i < maxRow; i++) { var nextLine = session.getLine(i + 1); text += " " + /^\s*(.*)$/.exec(nextLine)[1] || ""; @@ -529,7 +522,7 @@ var handleCursorMove = exports.onCursorMove = function(editor, e) { else { if (e && (util.onVisualLineMode || util.onVisualMode)) { editor.selection.clearSelection(); - util.normalMode(editor) + util.normalMode(editor); } handleCursorMove.running = true; diff --git a/lib/ace/keyboard/vim/keyboard.js b/lib/ace/keyboard/vim/keyboard.js index fab668d0..d184a6d3 100644 --- a/lib/ace/keyboard/vim/keyboard.js +++ b/lib/ace/keyboard/vim/keyboard.js @@ -12,7 +12,7 @@ var startCommands = { command: coreCommands.start }, 'I': { - command: coreCommands.startBeginning, + command: coreCommands.startBeginning }, 'a': { command: coreCommands.append @@ -42,20 +42,18 @@ exports.handler = { exec: function(editor) {cmds.inputBuffer.push(editor, key);} } }; } // wait for input - else if (key.length === 1 && (hashId == 0 || hashId === 4)) { //no modifier || shift - return {command: "null", stopEvent: false} + else if (key.length == 1 && (hashId == 0 || hashId == 4)) { //no modifier || shift + return {command: "null", stopEvent: false}; } else if (key == 'esc') { return {command: coreCommands.stop}; } } else { if (key == 'esc' || key == 'ctrl-[') { - data.state = 'start' - return {command: coreCommands.stop} + data.state = 'start'; + return {command: coreCommands.stop}; } } } -} - - +}; }); \ No newline at end of file diff --git a/lib/ace/keyboard/vim/maps/motions.js b/lib/ace/keyboard/vim/maps/motions.js index 42972870..f65ac015 100644 --- a/lib/ace/keyboard/vim/maps/motions.js +++ b/lib/ace/keyboard/vim/maps/motions.js @@ -14,37 +14,37 @@ var keepScrollPosition = function(editor, fn) { function Motion(getRange, type){ if (type == 'extend') - var extend = true + var extend = true; else - var reverse = type + var reverse = type; this.nav = function(editor) { var r = getRange(editor); if (!r) - return + return; if (!r.end) - var a = r + var a = r; else if (reverse) - var a = r.start + var a = r.start; else - var a = r.end + var a = r.end; - editor.clearSelection() + editor.clearSelection(); editor.moveCursorTo(a.row, a.column); } this.sel = function(editor){ var r = getRange(editor); if (!r) - return + return; if (extend) return editor.selection.setSelectionRange(r); if (!r.end) - var a = r + var a = r; else if (reverse) - var a = r.start + var a = r.start; else - var a = r.end + var a = r.end; editor.selection.selectTo(a.row, a.column); } @@ -54,61 +54,61 @@ var nonWordRe = /[\s.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/; var wordSeparatorRe = /[.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/; var whiteRe = /\s/; var StringStream = function(editor, cursor) { - var sel = editor.selection - this.range = sel.getRange() - cursor = cursor || sel.selectionLead + var sel = editor.selection; + this.range = sel.getRange(); + cursor = cursor || sel.selectionLead; this.row = cursor.row; this.col = cursor.column; var line = editor.session.getLine(this.row); var maxRow = editor.session.getLength() this.ch = line[this.col] || '\n' - this.skippedLines = 0 + this.skippedLines = 0; this.next = function() { - this.ch = line[++this.col] || this.handleNewLine(1) + this.ch = line[++this.col] || this.handleNewLine(1); //this.debug() - return this.ch + return this.ch; } this.prev = function() { - this.ch = line[--this.col] || this.handleNewLine(-1) + this.ch = line[--this.col] || this.handleNewLine(-1); //this.debug() - return this.ch + return this.ch; } this.peek = function(dir) { - var ch = line[this.col + dir] + var ch = line[this.col + dir]; if (ch) - return ch + return ch; if (dir == -1) - return '\n' + return '\n'; if (this.col == line.length - 1) - return '\n' - return editor.session.getLine(this.row + 1)[0] || '\n' + return '\n'; + return editor.session.getLine(this.row + 1)[0] || '\n'; } this.handleNewLine = function(dir) { if (dir == 1){ if (this.col == line.length) - return '\n' + return '\n'; if (this.row == maxRow - 1) - return '' - this.col = 0 - this.row ++ - line = editor.session.getLine(this.row) - this.skippedLines++ - return line[0] || '\n' + return ''; + this.col = 0; + this.row ++; + line = editor.session.getLine(this.row); + this.skippedLines++; + return line[0] || '\n'; } if (dir == -1) { if (this.row == 0) - return '' - this.row -- - line = editor.session.getLine(this.row) + return ''; + this.row --; + line = editor.session.getLine(this.row); this.col = line.length; - this.skippedLines-- - return '\n' + this.skippedLines--; + return '\n'; } } this.debug = function() { - console.log(line.substring(0, this.col)+'|'+this.ch+'\''+this.col+'\''+line.substr(this.col+1)) + console.log(line.substring(0, this.col)+'|'+this.ch+'\''+this.col+'\''+line.substr(this.col+1)); } } @@ -116,93 +116,93 @@ var Search = require("ace/search").Search; var search = new Search(); function find(editor, needle, dir) { - search.$options.needle = needle - search.$options.backwards = dir == -1 - return search.find(editor.session) + search.$options.needle = needle; + search.$options.backwards = dir == -1; + return search.find(editor.session); } -var lang = require("ace/lib/lang"); + var Range = require("ace/range").Range; module.exports = { "w": new Motion(function(editor) { - var str = new StringStream(editor) + var str = new StringStream(editor); if (str.ch && wordSeparatorRe.test(str.ch)) { while (str.ch && wordSeparatorRe.test(str.ch)) - str.next() + str.next(); } else { while (str.ch && !nonWordRe.test(str.ch)) - str.next() + str.next(); } while (str.ch && whiteRe.test(str.ch) && str.skippedLines < 2) - str.next() + str.next(); - str.skippedLines == 2 && str.prev() - return {column: str.col, row: str.row} + str.skippedLines == 2 && str.prev(); + return {column: str.col, row: str.row}; }), "W": new Motion(function(editor) { - var str = new StringStream(editor) + var str = new StringStream(editor); while(str.ch && !(whiteRe.test(str.ch) && !whiteRe.test(str.peek(1))) && str.skippedLines < 2) - str.next() + str.next(); if (str.skippedLines == 2) - str.prev() + str.prev(); else - str.next() + str.next(); return {column: str.col, row: str.row} }), "b": new Motion(function(editor) { - var str = new StringStream(editor) + var str = new StringStream(editor); - str.prev() + str.prev(); while (str.ch && whiteRe.test(str.ch) && str.skippedLines > -2) - str.prev() + str.prev(); if (str.ch && wordSeparatorRe.test(str.ch)) { while (str.ch && wordSeparatorRe.test(str.ch)) - str.prev() + str.prev(); } else { while (str.ch && !nonWordRe.test(str.ch)) - str.prev() + str.prev(); } str.ch && str.next(); - return {column: str.col, row: str.row} + return {column: str.col, row: str.row}; }), "B": new Motion(function(editor) { var str = new StringStream(editor) - str.prev() + str.prev(); while(str.ch && !(!whiteRe.test(str.ch) && whiteRe.test(str.peek(-1))) && str.skippedLines > -2) - str.prev() + str.prev(); if (str.skippedLines == -2) - str.next() + str.next(); - return {column: str.col, row: str.row} + return {column: str.col, row: str.row}; }, true), "e": new Motion(function(editor) { - var str = new StringStream(editor) + var str = new StringStream(editor); - str.next() + str.next(); while (str.ch && whiteRe.test(str.ch)) - str.next() + str.next(); if (str.ch && wordSeparatorRe.test(str.ch)) { while (str.ch && wordSeparatorRe.test(str.ch)) - str.next() + str.next(); } else { while (str.ch && !nonWordRe.test(str.ch)) - str.next() + str.next(); } - str.ch && str.prev() - return {column: str.col, row: str.row} + str.ch && str.prev(); + return {column: str.col, row: str.row}; }), "E": new Motion(function(editor) { - var str = new StringStream(editor) - str.next() + var str = new StringStream(editor); + str.next(); while(str.ch && !(!whiteRe.test(str.ch) && whiteRe.test(str.peek(1)))) - str.next() + str.next(); - return {column: str.col, row: str.row} + return {column: str.col, row: str.row}; }), "l": { @@ -265,10 +265,10 @@ module.exports = { var cursor = editor.getCursorPosition() var end = editor.session.$findClosingBracket(param, cursor, /paren/) if (!end) - return + return; var start = editor.session.$findOpeningBracket(editor.session.$brackets[param], cursor, /paren/) if (!start) - return + return; start.column ++; editor.selection.setSelectionRange(Range.fromPoints(start, end)) break @@ -277,10 +277,10 @@ module.exports = { case "/": var end = find(editor, param, 1) if (!end) - return + return; var start = find(editor, param, -1) if (!start) - return + return; editor.selection.setSelectionRange(Range.fromPoints(start.end, end.start)) break } @@ -299,28 +299,28 @@ module.exports = { case "(": case "{": case "[": - var cursor = editor.getCursorPosition() - var end = editor.session.$findClosingBracket(param, cursor, /paren/) + var cursor = editor.getCursorPosition(); + var end = editor.session.$findClosingBracket(param, cursor, /paren/); if (!end) - return - var start = editor.session.$findOpeningBracket(editor.session.$brackets[param], cursor, /paren/) + return; + var start = editor.session.$findOpeningBracket(editor.session.$brackets[param], cursor, /paren/); if (!start) - return + return; end.column ++; - editor.selection.setSelectionRange(Range.fromPoints(start, end)) - break + editor.selection.setSelectionRange(Range.fromPoints(start, end)); + break; case "'": case "\"": case "/": - var end = find(editor, param, 1) + var end = find(editor, param, 1); if (!end) - return - var start = find(editor, param, -1) + return; + var start = find(editor, param, -1); if (!start) - return + return; end.column ++; - editor.selection.setSelectionRange(Range.fromPoints(start.start, end.end)) - break + editor.selection.setSelectionRange(Range.fromPoints(start.start, end.end)); + break; } } }, @@ -528,19 +528,19 @@ module.exports = { "%": new Motion(function(editor){ var brRe = /[\[\]{}()]/g; var cursor = editor.getCursorPosition(); - var ch = editor.session.getLine(cursor.row)[cursor.column] - if (!brRe.test(ch)){ - var range = find(editor, brRe) + var ch = editor.session.getLine(cursor.row)[cursor.column]; + if (!brRe.test(ch)) { + var range = find(editor, brRe); if (!range) - return - cursor = range.start + return; + cursor = range.start; } var match = editor.session.findMatchingBracket({ row: cursor.row, column: cursor.column + 1 }); - return match + return match; }), "ctrl-d": { nav: function(editor, range, count, param) {