mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 08:15:00 +00:00
FIX: some changes in composer affect all visible text editors
This commit is contained in:
parent
12bb05ce68
commit
b7322b05a0
@ -246,15 +246,19 @@ export default Ember.Component.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.appEvents.on('composer:insert-text', text => this._addText(this._getSelected(), text));
|
if (this.get('composerEvents')) {
|
||||||
this.appEvents.on('composer:replace-text', (oldVal, newVal) => this._replaceText(oldVal, newVal));
|
this.appEvents.on('composer:insert-text', text => this._addText(this._getSelected(), text));
|
||||||
|
this.appEvents.on('composer:replace-text', (oldVal, newVal) => this._replaceText(oldVal, newVal));
|
||||||
|
}
|
||||||
this._mouseTrap = mouseTrap;
|
this._mouseTrap = mouseTrap;
|
||||||
},
|
},
|
||||||
|
|
||||||
@on('willDestroyElement')
|
@on('willDestroyElement')
|
||||||
_shutDown() {
|
_shutDown() {
|
||||||
this.appEvents.off('composer:insert-text');
|
if (this.get('composerEvents')) {
|
||||||
this.appEvents.off('composer:replace-text');
|
this.appEvents.off('composer:insert-text');
|
||||||
|
this.appEvents.off('composer:replace-text');
|
||||||
|
}
|
||||||
|
|
||||||
const mouseTrap = this._mouseTrap;
|
const mouseTrap = this._mouseTrap;
|
||||||
Object.keys(this.get('toolbar.shortcuts')).forEach(sc => mouseTrap.unbind(sc));
|
Object.keys(this.get('toolbar.shortcuts')).forEach(sc => mouseTrap.unbind(sc));
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
togglePreview="togglePreview"
|
togglePreview="togglePreview"
|
||||||
validation=validation
|
validation=validation
|
||||||
loading=composer.loading
|
loading=composer.loading
|
||||||
forcePreview=forcePreview}}
|
forcePreview=forcePreview
|
||||||
|
composerEvents=true}}
|
||||||
|
|
||||||
<div class="composer-bottom-right">
|
<div class="composer-bottom-right">
|
||||||
{{#if site.mobileView}}
|
{{#if site.mobileView}}
|
||||||
|
@ -62,6 +62,19 @@ function testCase(title, testFunc) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function composerTestCase(title, testFunc) {
|
||||||
|
componentTest(title, {
|
||||||
|
template: '{{d-editor value=value composerEvents=true}}',
|
||||||
|
setup() {
|
||||||
|
this.set('value', 'hello world.');
|
||||||
|
},
|
||||||
|
test(assert) {
|
||||||
|
const textarea = jumpEnd(this.$('textarea.d-editor-input')[0]);
|
||||||
|
testFunc.call(this, assert, textarea);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
testCase(`selecting the space before a word`, function(assert, textarea) {
|
testCase(`selecting the space before a word`, function(assert, textarea) {
|
||||||
textarea.selectionStart = 5;
|
textarea.selectionStart = 5;
|
||||||
textarea.selectionEnd = 7;
|
textarea.selectionEnd = 7;
|
||||||
@ -760,8 +773,19 @@ componentTest('emoji', {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
testCase("replace-text event", function(assert) {
|
testCase("replace-text event by default", function(assert) {
|
||||||
|
this.set('value', "red green blue");
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
this.container.lookup('app-events:main').trigger('composer:replace-text', 'green', 'yellow');
|
||||||
|
});
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
assert.equal(this.get('value'), 'red green blue');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
composerTestCase("replace-text event for composer", function(assert) {
|
||||||
this.set('value', "red green blue");
|
this.set('value', "red green blue");
|
||||||
|
|
||||||
andThen(() => {
|
andThen(() => {
|
||||||
@ -773,6 +797,7 @@ testCase("replace-text event", function(assert) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
// Tests to check cursor/selection after replace-text event.
|
// Tests to check cursor/selection after replace-text event.
|
||||||
const BEFORE = 'red green blue';
|
const BEFORE = 'red green blue';
|
||||||
@ -849,7 +874,7 @@ testCase("replace-text event", function(assert) {
|
|||||||
|
|
||||||
for (let i = 0; i < CASES.length; i++) {
|
for (let i = 0; i < CASES.length; i++) {
|
||||||
const CASE = CASES[i];
|
const CASE = CASES[i];
|
||||||
testCase(`replace-text event: ${CASE.description}`, function(assert, textarea) {
|
composerTestCase(`replace-text event: ${CASE.description}`, function(assert, textarea) {
|
||||||
this.set('value', BEFORE);
|
this.set('value', BEFORE);
|
||||||
setSelection(textarea, CASE.before);
|
setSelection(textarea, CASE.before);
|
||||||
andThen(() => {
|
andThen(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user