Deprecate duplicate functions from utils.

Closes #245
pull/427/head
Matthias Bussonnier 11 years ago
parent b521d76ebb
commit 5fadb67dda

@ -500,41 +500,13 @@ define([
};
var to_absolute_cursor_pos = function (cm, cursor) {
/**
* get the absolute cursor position from CodeMirror's col, ch
*/
if (!cursor) {
cursor = cm.getCursor();
}
var cursor_pos = cursor.ch;
for (var i = 0; i < cursor.line; i++) {
cursor_pos += cm.getLine(i).length + 1;
}
return cursor_pos;
console.warn('utils.to_absolute_cursor_pos(cm, pos) is deprecated us cm.indexFromPos(cursor)');
return cm.indexFromPos(cusrsor);
};
var from_absolute_cursor_pos = function (cm, cursor_pos) {
/**
* turn absolute cursor position into CodeMirror col, ch cursor
*/
var i, line, next_line;
var offset = 0;
for (i = 0, next_line=cm.getLine(i); next_line !== undefined; i++, next_line=cm.getLine(i)) {
line = next_line;
if (offset + next_line.length < cursor_pos) {
offset += next_line.length + 1;
} else {
return {
line : i,
ch : cursor_pos - offset,
};
}
}
// reached end, return endpoint
return {
line : i - 1,
ch : line.length - 1,
};
console.warn('utils.from_absolute_cursor_pos(cm, pos) is deprecated us cm.posFromIndex(index)');
return cm.posFromIndex(cursor_pos);
};
// http://stackoverflow.com/questions/2400935/browser-detection-in-javascript

@ -152,7 +152,7 @@ define([
// one kernel completion came back, finish_completing will be called with the results
// we fork here and directly call finish completing if kernel is busy
var cursor_pos = utils.to_absolute_cursor_pos(this.editor, cur);
var cursor_pos = this.editor.indexFromPos(cur);
if (this.skip_kernel_completion) {
this.finish_completing({ content: {
matches: [],
@ -181,7 +181,7 @@ define([
// adapted message spec replies don't have cursor position info,
// interpret end=null as current position,
// and negative start relative to that
end = utils.to_absolute_cursor_pos(this.editor, cur);
end = this.editor.indexFromPos(cur);
if (start === null) {
start = end;
} else if (start < 0) {
@ -202,8 +202,8 @@ define([
// append the introspection result, in order, at at the beginning of
// the table and compute the replacement range from current cursor
// positon and matched_text length.
var from = utils.from_absolute_cursor_pos(this.editor, start);
var to = utils.from_absolute_cursor_pos(this.editor, end);
var from = this.editor.posFromIndex(start);
var to = this.editor.posFromIndex(end);
for (i = matches.length - 1; i >= 0; --i) {
filtered_results.unshift({
str: matches[i],
@ -274,7 +274,7 @@ define([
// After everything is on the page, compute the postion.
// We put it above the code if it is too close to the bottom of the page.
var pos = this.editor.cursorCoords(
utils.from_absolute_cursor_pos(this.editor, start)
this.editor.posFromIndex(start)
);
var left = pos.left-3;
var top;

@ -201,7 +201,7 @@ define([
this.cancel_pending();
var editor = cell.code_mirror;
var cursor = editor.getCursor();
var cursor_pos = utils.to_absolute_cursor_pos(editor, cursor);
var cursor_pos = editor.indexFromPos(cursor);
var text = cell.get_text();
this._hide_if_no_docstring = hide_if_no_docstring;

Loading…
Cancel
Save