FIX: Improve windows double clicking on words in editor

This commit is contained in:
Robin Ward 2015-11-24 13:41:56 -05:00
parent 99c1aa2e85
commit 49bda0b17d
2 changed files with 25 additions and 9 deletions

View file

@ -299,14 +299,20 @@ export default Ember.Component.extend({
if (!this.get('ready')) { return; } if (!this.get('ready')) { return; }
const textarea = this.$('textarea.d-editor-input')[0]; const textarea = this.$('textarea.d-editor-input')[0];
const value = textarea.value;
const start = textarea.selectionStart; const start = textarea.selectionStart;
const end = textarea.selectionEnd; let end = textarea.selectionEnd;
const value = textarea.value.substring(start, end); // Windows selects the space after a word when you double click
const pre = textarea.value.slice(0, start); while (end > start && /\s/.test(value.charAt(end-1))) {
const post = textarea.value.slice(end); end--;
}
return { start, end, value, pre, post }; const selVal = value.substring(start, end);
const pre = value.slice(0, start);
const post = value.slice(end);
return { start, end, value: selVal, pre, post };
}, },
_selectText(from, length) { _selectText(from, length) {

View file

@ -62,6 +62,18 @@ function testCase(title, testFunc) {
}); });
} }
testCase(`selecting the space after a word`, function(assert, textarea) {
textarea.selectionStart = 0;
textarea.selectionEnd = 6;
click(`button.bold`);
andThen(() => {
assert.equal(this.get('value'), `**hello** world.`);
assert.equal(textarea.selectionStart, 2);
assert.equal(textarea.selectionEnd, 7);
});
});
testCase(`bold button with no selection`, function(assert, textarea) { testCase(`bold button with no selection`, function(assert, textarea) {
click(`button.bold`); click(`button.bold`);
andThen(() => { andThen(() => {
@ -231,10 +243,8 @@ componentTest('advanced code', {
test(assert) { test(assert) {
const textarea = this.$('textarea.d-editor-input')[0]; const textarea = this.$('textarea.d-editor-input')[0];
andThen(() => {
textarea.selectionStart = 0; textarea.selectionStart = 0;
textarea.selectionEnd = textarea.value.length; textarea.selectionEnd = textarea.value.length;
});
click('button.code'); click('button.code');
andThen(() => { andThen(() => {