FIX: bolding text when selection has a leading space

This commit is contained in:
Sam Saffron 2016-03-10 22:43:08 +11:00
parent a212540779
commit 7be90a885c
2 changed files with 19 additions and 2 deletions

View File

@ -360,14 +360,19 @@ export default Ember.Component.extend({
const textarea = this.$('textarea.d-editor-input')[0];
const value = textarea.value;
const start = textarea.selectionStart;
var start = textarea.selectionStart;
let end = textarea.selectionEnd;
// Windows selects the space after a word when you double click
// trim trailing spaces cause **test ** would be invalid
while (end > start && /\s/.test(value.charAt(end-1))) {
end--;
}
// trim leading spaces cause ** test** would be invalid
while(end > start && /\s/.test(value.charAt(start))) {
start++;
}
const selVal = value.substring(start, end);
const pre = value.slice(0, start);
const post = value.slice(end);

View File

@ -62,6 +62,18 @@ function testCase(title, testFunc) {
});
}
testCase(`selecting the space before a word`, function(assert, textarea) {
textarea.selectionStart = 5;
textarea.selectionEnd = 7;
click(`button.bold`);
andThen(() => {
assert.equal(this.get('value'), `hello **w**orld.`);
assert.equal(textarea.selectionStart, 8);
assert.equal(textarea.selectionEnd, 9);
});
});
testCase(`selecting the space after a word`, function(assert, textarea) {
textarea.selectionStart = 0;
textarea.selectionEnd = 6;