Skip to content

Commit

Permalink
patch bililiteRange to use selectionTracker, hopefully corrrectly thi…
Browse files Browse the repository at this point in the history
…s time
  • Loading branch information
dwachss committed Jan 3, 2014
1 parent a4a8746 commit 5c034c1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 0 additions & 2 deletions bililiteRange.ex.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ newline: function(line, select){
bililiteRange.ex = {}; // namespace for exporting utility functions

bililiteRange.fn.ex = function (commandstring, defaultaddress){
console.log('ex ',commandstring, this.bounds());
this.exMessage = '';
var state = this.exState();
// default address is generally the current line; 'bounds' means use the current bounds. '%' means the entire text
Expand All @@ -98,7 +97,6 @@ bililiteRange.fn.ex = function (commandstring, defaultaddress){
parsed.command.call(this, parsed.parameter, parsed.variant);
this.dispatch({type: 'excommand', command: command, range: this});
}, this);
console.log('after ex ', this.bounds());
return this; // allow for chaining
};

Expand Down
18 changes: 11 additions & 7 deletions jquery.sendkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,33 @@ $.fn.selectionTracker = function(bounds){
});
}
if (arguments.length > 0) rng.bounds(bounds); // change the saved selection without actually selecting
console.log(rng.bounds());
if (document.activeElement == this[0]) rng.select(); // explicitly select it if already active
return rng;
}

// monkey patch bililiteRange to reflect the saved range
var select = bililiteRange.fn.select;
var oldselect = bililiteRange.fn.select;
bililiteRange.fn.select = function(){
var $el = $(this.element());
if ($el.data('selectionTracker')) $el.selectionTracker(this.bounds());
return select.apply(this, arguments);
if (
$el.data('selectionTracker') &&
document.activeElement != $el[0]
){
$el.selectionTracker(this.bounds());
}
return oldselect.apply(this, arguments);
};
var bounds = bililiteRange.fn.bounds;
var oldbounds = bililiteRange.fn.bounds;
bililiteRange.fn.bounds = function(bounds){
var $el = $(this.element());
if (
$el.data('selectionTracker') && // if we are tracking the selection
document.activeElement != $el[0] && // and the real selection isn't here
bounds == 'selection' // and we want the selection anyway
){
return this.bounds($el.selectionTracker().bounds()); // use the saved selection
bounds = $el.selectionTracker().bounds(); // use the saved selection
}
return bounds.apply(this, arguments);
return oldbounds.call(this, bounds);
}

// monkey patch focus to actually focus the element, on the saved range
Expand Down
3 changes: 1 addition & 2 deletions jquery.vi.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ $.fn.vi = function(statusbar){
function executeCommand (rng, command){
// returns a function that will run command (if not defined, then will run whatever command is passed in when executed)
return function (text){
rng.selectionTracker().ex(command || text, 'bounds').scrollIntoView();
console.log('after executeCommand', rng.bounds());
rng.bounds('selection').ex(command || text, 'bounds').scrollIntoView();
return rng.exMessage;
};
}
Expand Down

0 comments on commit 5c034c1

Please sign in to comment.