--- a/frontend/js/bespin/editor/actions.js
+++ b/frontend/js/bespin/editor/actions.js
@@ -41,17 +41,17 @@ dojo.declare("bespin.editor.Actions", nu
this.editor = editor;
this.ignoreRepaints = false;
},
// this is a generic helper method used by various cursor-moving methods
handleCursorSelection: function(args) {
if (args.event.shiftKey) {
if (!this.editor.selection) this.editor.setSelection({ startPos: bespin.editor.utils.copyPos(args.pos) });
- this.editor.setSelection({ startPos: this.editor.selection.startPos, endPos: bespin.editor.utils.copyPos(this.editor.cursorManager.getScreenPosition())});
+ this.editor.setSelection({ startPos: this.editor.selection.startPos, endPos: bespin.editor.utils.copyPos(this.editor.cursorManager.getScreenPosition()) });
} else {
this.editor.setSelection(undefined);
}
},
moveCursor: function(moveType, args) {
var posData = this.editor.cursorManager[moveType]();
this.handleCursorSelection(args);
@@ -131,18 +131,18 @@ dojo.declare("bespin.editor.Actions", nu
redo: function() {
this.editor.undoManager.redo();
},
selectAll: function(args) {
// do nothing with an empty doc
if (this.editor.model.getMaxCols == 0) return;
- args.startPos = { col: 0, row: 0 };
- args.endPos = { col: this.editor.model.getRowLength(this.editor.model.getRowCount() - 1), row: this.editor.model.getRowCount() - 1 };
+ args.startPos = { row: 0, col: 0 };
+ args.endPos = { row: this.editor.model.getRowCount() - 1, col: this.editor.model.getRowLength(this.editor.model.getRowCount() - 1) };
this.select(args);
},
select: function(args) {
if (args.startPos) {
this.editor.setSelection({ startPos: args.startPos, endPos: args.endPos });
this.editor.cursorManager.moveCursor(args.endPos);
@@ -195,18 +195,18 @@ dojo.declare("bespin.editor.Actions", nu
var undoOperation = undoArgs;
this.editor.undoManager.addUndoOperation(new bespin.editor.UndoItem(undoOperation, redoOperation));
},
// this function can only be called by editor.undoManager for undo insertTab in the case of beeing nothing selected
removeTab: function(args) {
var tabWidth = args.tabWidth;
- this.editor.model.deleteCharacters({row: args.pos.row, col: args.pos.col}, tabWidth);
- this.editor.cursorManager.moveCursor({row: args.pos.row, col: args.pos.col});
+ this.editor.model.deleteCharacters({ row: args.pos.row, col: args.pos.col }, tabWidth);
+ this.editor.cursorManager.moveCursor({ row: args.pos.row, col: args.pos.col });
this.repaint();
args.action = "removeTab";
var redoOperation = args;
var undoArgs = { action: "insertTab", undoInsertTab: true, queued: args.queued, pos: bespin.editor.utils.copyPos(args.pos),
modelPos: bespin.editor.utils.copyPos(args.modelPos), tab: args.tab, tabWidth: args.tabWidth };
var undoOperation = undoArgs;
@@ -234,20 +234,20 @@ dojo.declare("bespin.editor.Actions", nu
if (!historyIndent) {
var row = this.editor.model.getRowArray(y).join("");
var match = /^(\s+).*/.exec(row);
var leadingWhitespaceLength = 0;
if (match && match.length == 2) {
leadingWhitespaceLength = match[1].length;
}
var charsToInsert = (leadingWhitespaceLength % tabWidth ? tabWidth - (leadingWhitespaceLength % tabWidth) : tabWidth);
- this.editor.model.insertCharacters({row: y, col: 0}, tab.substring(0, charsToInsert));
+ this.editor.model.insertCharacters({ row: y, col: 0 }, tab.substring(0, charsToInsert));
newHistoryIndent.push(charsToInsert);
} else {
- this.editor.model.insertCharacters({row: y, col: 0}, tab.substring(0, historyIndent[y - startRow]));
+ this.editor.model.insertCharacters({ row: y, col: 0 }, tab.substring(0, historyIndent[y - startRow]));
}
}
if (!fakeSelection) {
selection.startPos.col += (historyIndent ? historyIndent[0] : tab.length);
selection.endPos.col += (historyIndent ? historyIndent[historyIndent.length-1] : tab.length);
this.editor.setSelection(selection);
}
@@ -269,17 +269,17 @@ dojo.declare("bespin.editor.Actions", nu
var historyIndent = args.historyIndent || false;
if (!historyIndent) {
var newHistoryIndent = [];
}
var selection = args.selection || this.editor.getSelection();
var fakeSelection = args.fakeSelection || false;
if (!selection) {
fakeSelection = true;
- selection = {startPos: {row: args.pos.row, col: args.pos.col}, endPos: {row: args.pos.row, col: args.pos.col}};
+ selection = { startPos: { row: args.pos.row, col: args.pos.col }, endPos: { row: args.pos.row, col: args.pos.col } };
}
var startRow = selection.startPos.row;
var endRow = selection.endPos.row;
var tabWidth = parseInt(_settings.get('tabsize') || bespin.defaultTabSize); // TODO: global needs fixing
for (var y = startRow; y <= endRow; y++) {
if (historyIndent) {
var charsToDelete = historyIndent[y - startRow];
@@ -290,17 +290,17 @@ dojo.declare("bespin.editor.Actions", nu
if (match && match.length == 2) {
leadingWhitespaceLength = match[1].length;
}
var charsToDelete = leadingWhitespaceLength >= tabWidth ? (leadingWhitespaceLength % tabWidth ? leadingWhitespaceLength % tabWidth : tabWidth) : leadingWhitespaceLength;
newHistoryIndent.push(charsToDelete);
}
if (charsToDelete) {
- this.editor.model.deleteCharacters({row: y, col: 0}, charsToDelete);
+ this.editor.model.deleteCharacters({ row: y, col: 0 }, charsToDelete);
}
if (y == startRow) {
selection.startPos.col = Math.max(0, selection.startPos.col - charsToDelete);
}
if (y == endRow) {
selection.endPos.col = Math.max(0, selection.endPos.col - charsToDelete);
}
if (y == args.pos.row) {
--- a/frontend/js/bespin/editor/cursor.js
+++ b/frontend/js/bespin/editor/cursor.js
@@ -1,17 +1,17 @@
dojo.provide("bespin.editor.cursor");
// ** {{{ bespin.editor.CursorManager }}} **
//
// Handles the position of the cursor, hiding the complexity of translating between screen and model positions and so forth
dojo.declare("bespin.editor.CursorManager", null, {
constructor: function(editor) {
this.editor = editor;
- this.position = { col: 0, row: 0 };
+ this.position = { row: 0, col: 0 };
},
getScreenPosition: function() {
return this.position;
},
getModelPosition: function() {
var pos = this.position;
@@ -24,17 +24,17 @@ dojo.declare("bespin.editor.CursorManage
var toInsert = this.editor.tabstop - (curCol % this.editor.tabstop);
curCol += toInsert - 1;
tabspaces += toInsert - 1;
}
curCol++;
if (curCol >= pos.col) break;
}
if (tabspaces > 0) {
- return { col: pos.col = pos.col - tabspaces, row: pos.row };
+ return { row: pos.row, col: pos.col = pos.col - tabspaces };
} else {
return bespin.editor.utils.copyPos(pos);
}
},
moveToLineStart: function() {
var oldPos = bespin.editor.utils.copyPos(this.position);
@@ -64,34 +64,34 @@ dojo.declare("bespin.editor.CursorManage
this.moveCursor({ col: this.editor.ui.getRowScreenLength(oldPos.row) });
return { oldPos: oldPos, newPos: bespin.editor.utils.copyPos(this.position) };
},
moveToTop: function() {
var oldPos = bespin.editor.utils.copyPos(this.position);
- this.editor.cursorManager.moveCursor({ col: 0, row: 0 });
+ this.editor.cursorManager.moveCursor({ row: 0, col: 0 });
return { oldPos: oldPos, newPos: bespin.editor.utils.copyPos(this.position) };
},
moveToBottom: function() {
var oldPos = bespin.editor.utils.copyPos(this.position);
var row = this.editor.model.getRowCount() - 1;
- this.editor.cursorManager.moveCursor({ row: row, col: this.editor.ui.getRowScreenLength(row)});
+ this.editor.cursorManager.moveCursor({ row: row, col: this.editor.ui.getRowScreenLength(row) });
return { oldPos: oldPos, newPos: bespin.editor.utils.copyPos(this.position) };
},
moveUp: function() {
var oldPos = bespin.editor.utils.copyPos(this.position);
- this.moveCursor({ col: oldPos.col, row: oldPos.row - 1 });
+ this.moveCursor({ row: oldPos.row - 1, col: oldPos.col });
if (bespin.get("settings").isOn(bespin.get("settings").get('strictlines')) && this.position.col > this.editor.ui.getRowScreenLength(this.position.row)) {
this.moveToLineEnd();
}
return { oldPos: oldPos, newPos: bespin.editor.utils.copyPos(this.position) };
},
@@ -110,17 +110,17 @@ dojo.declare("bespin.editor.CursorManage
moveLeft: function() {
var oldPos = bespin.editor.utils.copyPos(this.position);
// start of the line so move up
if (bespin.get("settings").isOn(bespin.get("settings").get('strictlines')) && (this.position.col == 0)) {
this.moveUp();
if (oldPos.row > 0) this.moveToLineEnd();
} else {
- this.moveCursor({ col: Math.max(0, oldPos.col - 1), row: oldPos.row });
+ this.moveCursor({ row: oldPos.row, col: Math.max(0, oldPos.col - 1) });
}
return { oldPos: oldPos, newPos: bespin.editor.utils.copyPos(this.position) }
},
moveRight: function() {
var oldPos = bespin.editor.utils.copyPos(this.position);
@@ -133,25 +133,25 @@ dojo.declare("bespin.editor.CursorManage
}
return { oldPos: oldPos, newPos: bespin.editor.utils.copyPos(this.position) }
},
movePageUp: function() {
var oldPos = bespin.editor.utils.copyPos(this.position);
- this.moveCursor({ row: Math.max(this.editor.ui.firstVisibleRow - this.editor.ui.visibleRows, 0)});
+ this.moveCursor({ row: Math.max(this.editor.ui.firstVisibleRow - this.editor.ui.visibleRows, 0) });
return { oldPos: oldPos, newPos: bespin.editor.utils.copyPos(this.position) }
},
movePageDown: function() {
var oldPos = bespin.editor.utils.copyPos(this.position);
- this.moveCursor({ row: Math.min(this.position.row + this.editor.ui.visibleRows, this.editor.model.getRowCount() - 1)});
+ this.moveCursor({ row: Math.min(this.position.row + this.editor.ui.visibleRows, this.editor.model.getRowCount() - 1) });
return { oldPos: oldPos, newPos: bespin.editor.utils.copyPos(this.position) }
},
smartMoveLeft: function() {
var oldPos = bespin.editor.utils.copyPos(this.position);
var row = this.editor.ui.getRowString(oldPos.row);
@@ -286,17 +286,17 @@ dojo.declare("bespin.editor.CursorManage
// we need to track the cursor position separately because we're stepping through the array, not the row string
var curCol = 0;
for (var i = 0; i < rowArray.length; i++) {
if (rowArray[i].charCodeAt(0) == 9) {
// if current character in the array is a tab, work out the white space between here and the tab stop
var toInsert = this.editor.tabstop - (curCol % this.editor.tabstop);
// if the passed column is in the whitespace between the tab and the tab stop, it's an invalid position
- if (col > curCol && col < (curCol + toInsert)) {
+ if ((col > curCol) && (col < (curCol + toInsert))) {
return { left: curCol, right: curCol + toInsert };
}
curCol += toInsert - 1;
}
curCol++;
}
--- a/frontend/js/bespin/editor/editor.js
+++ b/frontend/js/bespin/editor/editor.js
@@ -480,17 +480,17 @@ dojo.declare("bespin.editor.UI", null, {
if (bespin.get('settings').isSettingOn('strictlines')) {
var maxcol = this.getRowScreenLength(y);
if (x >= maxcol) {
x = this.getRowScreenLength(y);
}
}
}
- return { col: x, row: y };
+ return { row: y, col: x };
},
mouseDownSelect: function(e) {
var clientY = e.clientY - this.getTopOffset();
var clientX = e.clientX - this.getLeftOffset();
if (this.overXScrollBar || this.overYScrollBar) return;
@@ -591,17 +591,17 @@ dojo.declare("bespin.editor.UI", null, {
this.xoffset = -x;
} else if ((Math.abs(this.xoffset) + cwidth) < (x + (this.charWidth * 2))) { // current col after right-most visible col
this.xoffset = -((x + (this.charWidth * 2)) - cwidth);
}
},
handleFocus: function(e) {
this.editor.model.clear();
- this.editor.model.insertCharacters({ row: 0, col: 0}, e.type);
+ this.editor.model.insertCharacters({ row: 0, col: 0 }, e.type);
},
handleScrollBars: function(e) {
var clientY = e.clientY - this.getTopOffset();
var clientX = e.clientX - this.getLeftOffset();
var oldX = this.overXScrollBar;
var oldY = this.overYScrollBar;
@@ -1349,32 +1349,32 @@ dojo.declare("bespin.editor.API", null,
constructor: function(container, opts) {
this.tabstop = 4; // tab stops every 4 columns; TODO: make this a setting
this.opts = opts || {};
this.container = dojo.byId(container);
this.model = new bespin.editor.DocumentModel();
- dojo.byId(container).innerHTML = "<canvas id='canvas' moz-opaque='true' tabindex='-1'></canvas>";
+ dojo.byId(container).innerHTML = '<canvas id="canvas" moz-opaque="true" tabindex="-1"></canvas>';
this.canvas = dojo.byId(container).firstChild;
while (this.canvas && this.canvas.nodeType != 1) this.canvas = this.canvas.nextSibling;
this.ui = new bespin.editor.UI(this);
this.theme = bespin.editor.themes['default'];
this.cursorManager = new bespin.editor.CursorManager(this);
this.editorKeyListener = new bespin.editor.DefaultEditorKeyListener(this);
this.undoManager = new bespin.editor.UndoManager(this);
this.customEvents = new bespin.editor.Events(this);
this.ui.installKeyListener(this.editorKeyListener);
- this.model.insertCharacters({row: 0, col: 0}, " ");
+ this.model.insertCharacters({ row: 0, col: 0 }, " ");
dojo.connect(this.canvas, "blur", dojo.hitch(this, function(e) { this.setFocus(false); }));
dojo.connect(this.canvas, "focus", dojo.hitch(this, function(e) { this.setFocus(true); }));
bespin.editor.clipboard.setup(this); // setup the clipboard
this.paint();
@@ -1408,17 +1408,17 @@ dojo.declare("bespin.editor.API", null,
this.cursorManager.moveCursor(data.cursor);
this.setSelection(data.selection);
this.ui.yoffset = data.offset.y;
this.ui.xoffset = data.offset.x;
this.paint();
},
getCurrentView: function() {
- return { cursor: this.getCursorPos(), offset: { x: this.ui.xoffset, y: this.ui.yoffset }, selection: this.selection};
+ return { cursor: this.getCursorPos(), offset: { x: this.ui.xoffset, y: this.ui.yoffset }, selection: this.selection };
},
// helper to get text
getSelectionAsText: function() {
var selectionText = '';
var selectionObject = this.getSelection();
if (selectionObject) {
selectionText = this.model.getChunk(selectionObject);
--- a/frontend/js/bespin/editor/model.js
+++ b/frontend/js/bespin/editor/model.js
@@ -230,25 +230,25 @@ dojo.declare("bespin.editor.DocumentMode
var startCol, endCol;
// get the first line
startCol = startPos.col;
var row = this.getRowArray(startPos.row);
endCol = (endPos.row == startPos.row) ? endPos.col : row.length;
if (endCol > row.length) endCol = row.length;
- this.deleteCharacters({ row: startPos.row, col: startCol}, endCol - startCol);
+ this.deleteCharacters({ row: startPos.row, col: startCol }, endCol - startCol);
// get the end line
if (startPos.row != endPos.row) {
startCol = 0;
endCol = endPos.col;
row = this.getRowArray(endPos.row);
if (endCol > row.length) endCol = row.length;
- this.deleteCharacters({ row: endPos.row, col: startCol}, endCol - startCol);
+ this.deleteCharacters({ row: endPos.row, col: startCol }, endCol - startCol);
}
// remove any lines in-between
if ((endPos.row - startPos.row) > 1) this.deleteRows(startPos.row + 1, endPos.row - startPos.row - 1);
// join the rows
if (endPos.row != startPos.row) this.joinRow(startPos.row);