Save state

This commit is contained in:
Garen Torikian 2012-12-12 15:55:29 -08:00 committed by nightwing
commit b63b84292a
2 changed files with 89 additions and 8 deletions

View file

@ -227,7 +227,7 @@ var Document = function(text) {
* [Given a range within the document, this function returns all the text within that range as a single string.]{: #Document.getTextRange.desc}
* @param {Range} range The range to work with
*
*
* @returns {String}
**/
this.getTextRange = function(range) {
if (range.start.row == range.end.row) {

View file

@ -780,15 +780,27 @@ var Editor = function(renderer, session) {
this.$processRow = function(cursor, rows) {
var edit = false;
var checkedRows = [];
for (var r = 0, rowCount = rows.length; r < rowCount; 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
var row = rows[r];
if (checkedRows.indexOf(row) > -1)
continue;
var cellWidthObj = this.$findCellWidthsForBlock(cursor, row);
var cellWidths = this.$setBlockCellWidthsToMax(cellWidthObj.cellWidths);
var rowIndex = cellWidthObj.firstRow;
for (var w = 0, l = cellWidths.length; w < l; w++) {
var widths = cellWidths[w];
checkedRows.push(rowIndex);
edit = this.$adjustRow(edit, rowIndex, widths);
rowIndex++;
}
}
return edit;
};
this.$findCellWidthsForBlock = function(cursor, row) {
@ -913,6 +925,62 @@ var Editor = function(renderer, session) {
return rowTabs;
};
this.$adjustRow = function(edit, row, widths) {
var rowTabs = this.$tabsForRow(row);
if (rowTabs.length == 0)
return edit;
var bias = 0, location = -1;
// this always only contains two elements, so we're safe in the loop below
var expandedSet = this.$izip(widths, rowTabs);
for (var i = 0, l = expandedSet.length; i < l; i++) {
var w = expandedSet[i][0], it = expandedSet[i][1];
location += 1 + w;
it += bias;
var difference = location - it;
if (difference == 0)
continue;
var endTabPoint = this.textPoint(row, it);
//console.log("wot " + row + " " + " " + it + " " + endTabPoint);
var partialLine = this.session.getLine(endTabPoint)
}
/*
end_tab_point = view.text_point(row, it)
partial_line = view.substr(view.line(end_tab_point))[0:it]
stripped_partial_line = partial_line.rstrip()
ispaces = len(partial_line) - len(stripped_partial_line)
if difference > 0:
if not edit:
edit = view.begin_edit()
#put the spaces after the tab and then delete the tab, so any insertion
#points behave as expected
view.insert(edit, end_tab_point+1, (' ' * difference) + "\t")
view.erase(edit, sublime.Region(end_tab_point, end_tab_point + 1))
bias += difference
if difference < 0 and ispaces >= -difference:
if not edit:
edit = view.begin_edit()
view.erase(edit, sublime.Region(end_tab_point, end_tab_point + difference))
bias += difference
*/
return edit;
};
this.textPoint = function(row, col) {
var selRange = new Range(0, 0, row, col);
var text = this.session.getTextRange(selRange);
return text.length;
};
// the is a (naive) Python port--but works for these purposes
this.$izip_longest = function(iterables) {
var longest = iterables[0].length;
@ -942,6 +1010,19 @@ var Editor = function(renderer, session) {
return expandedSet;
};
// an even more (naive) Python port
this.$izip = function(widths, tabs) {
// grab the shorter size
var size = widths.length >= tabs.length ? tabs.length : widths.length;
var expandedSet = [];
for (var i = 0; i < size; i++) {
var set = [ widths[i], tabs[i] ];
expandedSet.push(set);
}
return expandedSet;
};
this.onTextInput = function(text) {
this.keyBinding.onTextInput(text);
};