Hell yes, get all the Python implementation out of the way
This commit is contained in:
parent
cb5a8a4be4
commit
18d12d5375
1 changed files with 132 additions and 47 deletions
|
|
@ -774,89 +774,174 @@ var Editor = function(renderer, session) {
|
||||||
// todo: support multicursor
|
// todo: support multicursor
|
||||||
var row = cursor.row;
|
var row = cursor.row;
|
||||||
|
|
||||||
this.$processRow([row]);
|
this.$processRow(cursor, [row]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.$processRow = function(rows) {
|
this.$processRow = function(cursor, rows) {
|
||||||
for (var r = 0, rowCount = rows.length; r < rowCount; r++) {
|
for (var r = 0, rowCount = rows.length; r < rowCount; r++) {
|
||||||
var cellWidthObj = this.$findCellWidthsForBlock(rows[r]);
|
var cellWidthObj = this.$findCellWidthsForBlock(cursor, rows[r]);
|
||||||
|
cellWidthObj.cellWidths = this.$setBlockCellWidthsToMax(cellWidthObj.cellWidths);
|
||||||
|
console.log(cellWidthObj.cellWidths)
|
||||||
|
//for widths in cell_widths_by_row:
|
||||||
|
// checked_rows.add(row_index)
|
||||||
|
// edit = adjust_row(view, edit, row_index, widths)
|
||||||
|
// row_index += 1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$findCellWidthsForBlock = function(row, tabString) {
|
this.$findCellWidthsForBlock = function(cursor, row) {
|
||||||
var cellWidths = [], widths;
|
var cellWidths = [], widths;
|
||||||
|
|
||||||
// starting row and backward
|
// starting row and backward
|
||||||
var row_iter = row
|
var rowIter = row;
|
||||||
while (row_iter >= 0) {
|
while (rowIter >= 0) {
|
||||||
widths = this.$cellWidthsForRow(row_iter);
|
widths = this.$cellWidthsForRow(cursor, rowIter);
|
||||||
if (len(widths) == 0)
|
if (widths.length == 0)
|
||||||
break;
|
break;
|
||||||
cellWidths.unshift(widths);
|
|
||||||
row_iter--;
|
|
||||||
}
|
|
||||||
|
|
||||||
first_row = row_iter++;
|
cellWidths.unshift(widths);
|
||||||
|
rowIter--;
|
||||||
|
}
|
||||||
|
var firstRow = rowIter + 1;
|
||||||
|
|
||||||
// forward (not including starting row)
|
// forward (not including starting row)
|
||||||
row_iter = row;
|
rowIter = row;
|
||||||
var num_rows = lines_in_buffer(view);
|
var numRows = this.session.getLength();
|
||||||
|
|
||||||
while (row_iter < num_rows - 1) {
|
while (rowIter < numRows - 1) {
|
||||||
row_iter++;
|
rowIter++;
|
||||||
widths = this.$cellWidthsForRow(row_iter);
|
|
||||||
if (len(widths) == 0)
|
widths = this.$cellWidthsForRow(cursor, rowIter);
|
||||||
|
if (widths.length == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
cellWidths.push(widths);
|
cellWidths.push(widths);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {cellWidths: cellWidths, firstRow: firstRow};
|
return { cellWidths: cellWidths, firstRow: firstRow };
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$cellWidthsForRow = function(row) {
|
this.$cellWidthsForRow = function(cursor, row) {
|
||||||
var selectionColumns = this.$selectionColumnsForRow(row);
|
var selectionColumns = this.$selectionColumnsForRow(cursor, row);
|
||||||
//var tabs = [-1] + this.$tabsForRow(row);
|
// todo: support multicursor
|
||||||
//widths = [0] * (len(tabs) - 1);
|
|
||||||
//line = view.substr(view.line(view.text_point(row,0)))
|
var tabs = [-1].concat(this.$tabsForRow(row));
|
||||||
//for (var i = 0, len = tabs.length; i < len; i++) {
|
var widths = tabs.map(function (el) { return 0; } ).slice(1);
|
||||||
//left_edge = tabs[i]+1
|
var line = this.session.getLine(row);
|
||||||
//right_edge = tabs[i+1]
|
|
||||||
//rightmost_selection = rightmost_selection_in_cell(selection_columns, right_edge)
|
for (var i = 0, len = tabs.length - 1; i < len; i++) {
|
||||||
//cell = line[left_edge:right_edge]
|
var leftEdge = tabs[i]+1;
|
||||||
//widths[i] = max(len(cell.rstrip()), rightmost_selection - left_edge)
|
var rightEdge = tabs[i+1];
|
||||||
//}
|
|
||||||
//return widths;
|
var rightmostSelection = this.$rightmostSelectionInCell(selectionColumns, rightEdge);
|
||||||
|
var cell = line.substring(leftEdge, rightEdge);
|
||||||
|
widths[i] = Math.max(cell.replace(/\s+$/g,'').length, rightmostSelection - leftEdge);
|
||||||
|
}
|
||||||
|
|
||||||
|
return widths;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$selectionColumnsForRow = function(row, tabString) {
|
this.$selectionColumnsForRow = function(cursor, row) {
|
||||||
var selections = [];
|
var selections = [];
|
||||||
// todo: support multicursor
|
// todo: support multicursor
|
||||||
console.log("roar");
|
selections.push(cursor.column + 1);
|
||||||
console.log(this.getCursorPositionScreen());
|
|
||||||
//for s in view.sel():
|
|
||||||
//if (s.empty())
|
|
||||||
//r, c =view.rowcol(s.a)
|
|
||||||
//if (r == row)
|
|
||||||
// selections.append(c)
|
|
||||||
return selections;
|
return selections;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$tabsForRow = function(row, tabString) {
|
this.$setBlockCellWidthsToMax = function(cellWidths) {
|
||||||
var rowTabs = [];
|
var startingNewBlock = true, blockStartRow, blockEndRow, maxWidth;
|
||||||
|
|
||||||
var matches = session.getLine(row).match(new RegExp(tabString, "g"));
|
var columnInfo = this.$izip_longest(cellWidths);
|
||||||
|
|
||||||
if (matches !== null) {
|
for (var c = 0, l = columnInfo.length; c < l; c++) {
|
||||||
for (var m = 0, matchLength = matches.length; m < matchLength; m++) {
|
var column = columnInfo[c];
|
||||||
rowTabs.push(matches[m].length);
|
// add an extra None to the end so that the end of the column automatically
|
||||||
|
// finishes a block
|
||||||
|
column.push(NaN);
|
||||||
|
|
||||||
|
for (var r = 0, s = column.length; r < s; r++) {
|
||||||
|
var width = column[r];
|
||||||
|
if (startingNewBlock) {
|
||||||
|
blockStartRow = r;
|
||||||
|
maxWidth = 0;
|
||||||
|
startingNewBlock = false;
|
||||||
|
}
|
||||||
|
if (isNaN(width)) {
|
||||||
|
// block ended
|
||||||
|
blockEndRow = r;
|
||||||
|
|
||||||
|
for (var j = blockStartRow; j < blockEndRow; j++) {
|
||||||
|
cellWidths[j][c] = maxWidth;
|
||||||
|
}
|
||||||
|
startingNewBlock = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
maxWidth = Math.max(maxWidth, width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return cellWidths;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$rightmostSelectionInCell = function(selectionColumns, cellRightEdge) {
|
||||||
|
var rightmost = 0;
|
||||||
|
|
||||||
|
if (selectionColumns.length) {
|
||||||
|
var lengths = [];
|
||||||
|
for (var s = 0, length = selectionColumns.length; s < length; s++) {
|
||||||
|
if (selectionColumns[s] <= cellRightEdge)
|
||||||
|
lengths.push(s);
|
||||||
|
else
|
||||||
|
lengths.push(0);
|
||||||
|
}
|
||||||
|
rightmost = Math.max.apply(Math, lengths);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rightmost;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$tabsForRow = function(row) {
|
||||||
|
var rowTabs = [], line = this.session.getLine(row),
|
||||||
|
re = /\t/g, match;
|
||||||
|
|
||||||
|
while ((match = re.exec(line)) != null) {
|
||||||
|
rowTabs.push(match.index);
|
||||||
|
}
|
||||||
|
|
||||||
return rowTabs;
|
return rowTabs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// the is a (naive) Python port--but works for these purposes
|
||||||
|
this.$izip_longest = function(iterables) {
|
||||||
|
var longest = iterables[0].length;
|
||||||
|
var iterablesLength = iterables.length;
|
||||||
|
|
||||||
|
for (var i = 1; i < iterablesLength; i++) {
|
||||||
|
var iLength = iterables[i].length;
|
||||||
|
if (iLength > longest)
|
||||||
|
longest = iLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
var expandedSet = [];
|
||||||
|
|
||||||
|
for (var l = 0; l < longest; l++) {
|
||||||
|
var set = [];
|
||||||
|
for (var i = 0; i < iterablesLength; i++) {
|
||||||
|
if (iterables[i][l] === "")
|
||||||
|
set.push(NaN);
|
||||||
|
else
|
||||||
|
set.push(iterables[i][l]);
|
||||||
|
}
|
||||||
|
|
||||||
|
expandedSet.push(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return expandedSet;
|
||||||
|
};
|
||||||
|
|
||||||
this.onTextInput = function(text) {
|
this.onTextInput = function(text) {
|
||||||
this.keyBinding.onTextInput(text);
|
this.keyBinding.onTextInput(text);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue