mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FIX: Improve windows double clicking on words in editor
This commit is contained in:
parent
99c1aa2e85
commit
49bda0b17d
2 changed files with 25 additions and 9 deletions
|
@ -299,14 +299,20 @@ export default Ember.Component.extend({
|
|||
if (!this.get('ready')) { return; }
|
||||
|
||||
const textarea = this.$('textarea.d-editor-input')[0];
|
||||
const value = textarea.value;
|
||||
const start = textarea.selectionStart;
|
||||
const end = textarea.selectionEnd;
|
||||
let end = textarea.selectionEnd;
|
||||
|
||||
const value = textarea.value.substring(start, end);
|
||||
const pre = textarea.value.slice(0, start);
|
||||
const post = textarea.value.slice(end);
|
||||
// Windows selects the space after a word when you double click
|
||||
while (end > start && /\s/.test(value.charAt(end-1))) {
|
||||
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) {
|
||||
|
|
|
@ -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) {
|
||||
click(`button.bold`);
|
||||
andThen(() => {
|
||||
|
@ -231,10 +243,8 @@ componentTest('advanced code', {
|
|||
|
||||
test(assert) {
|
||||
const textarea = this.$('textarea.d-editor-input')[0];
|
||||
andThen(() => {
|
||||
textarea.selectionStart = 0;
|
||||
textarea.selectionEnd = textarea.value.length;
|
||||
});
|
||||
|
||||
click('button.code');
|
||||
andThen(() => {
|
||||
|
|
Loading…
Reference in a new issue