Skip to content

Commit

Permalink
Fix caret jumping to end while inserting text
Browse files Browse the repository at this point in the history
  • Loading branch information
Mottie committed Jun 6, 2015
1 parent f1f7ce4 commit 5ec0df8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
28 changes: 26 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ module.exports = function(grunt) {
'!languages/*.untranslated.js'
]
}
},
greyLayouts: {
options: {
banner: nomod + '/*! jQuery UI Virtual Keyboard - Microsoft Generated Layouts */\n'
},
files: {
'dist/layouts/keyboard-layouts-greywyvern.min.js': [
'layouts/keyboard-layouts-greywyvern.js',
'languages/*.js',
'!languages/_language_template.js',
'!languages/*.untranslated.js'
]
}
}
},

Expand Down Expand Up @@ -125,17 +138,28 @@ module.exports = function(grunt) {
flatten: true
}]
},
layouts: {
splitLayouts: {
files: [{
expand: true,
cwd: '',
src: [ 'layouts/*.js', '!layouts/_layout_template.js' ],
src: [ 'layouts/*.js', '!layouts/_layout_template.js', '!layouts/keyboard-layouts-greywyvern.js' ],
dest: 'dist/layouts/',
ext: '.min.js',
extDot: 'last',
flatten: true
}]
},
greyLayout: {
files: [{
expand: true,
cwd: '',
src: [ 'dist/layouts/keyboard-layouts-greywyvern.min.js' ],
dest: 'dist/layouts/',
ext: '.js',
extDot: 'last',
flatten: true
}]
},
languages: {
files: [{
expand: true,
Expand Down
2 changes: 1 addition & 1 deletion dist/js/jquery.keyboard.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/layouts/keyboard-layouts-greywyvern.min.js

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions js/jquery.keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ var $keyboard = $.keyboard = function(el, options){
bksp = isBksp && pos.start === pos.end;
txt = isBksp ? '' : txt;
val = val.substr(0, pos.start - (bksp ? 1 : 0)) + txt + val.substr(pos.end);
t = pos.start + (bksp ? -1 : val.length);
t = pos.start + (bksp ? -1 : txt.length);

base.$preview.val( val );
base.saveCaret( t, t ); // save caret in case of bksp
Expand Down Expand Up @@ -1003,7 +1003,6 @@ var $keyboard = $.keyboard = function(el, options){
pos = $keyboard.caret( base.$preview ),
layout = $keyboard.builtLayouts[base.layout],
len = val.length; // save original content length

// return if val is empty; fixes #352
if (val === '') { return val; }

Expand Down Expand Up @@ -1062,7 +1061,6 @@ var $keyboard = $.keyboard = function(el, options){
pos.end += val.length - len;
base.$preview.val(val);
base.saveCaret( pos.start, pos.end );

// set scroll to keep caret in view
base.setScroll();

Expand Down

0 comments on commit 5ec0df8

Please sign in to comment.