mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:49:14 +08: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));
|
||||
this.appEvents.on('composer:replace-text', (oldVal, newVal) => this._replaceText(oldVal, newVal));
|
||||
if (this.get('composerEvents')) {
|
||||
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;
|
||||
},
|
||||
|
||||
@on('willDestroyElement')
|
||||
_shutDown() {
|
||||
this.appEvents.off('composer:insert-text');
|
||||
this.appEvents.off('composer:replace-text');
|
||||
if (this.get('composerEvents')) {
|
||||
this.appEvents.off('composer:insert-text');
|
||||
this.appEvents.off('composer:replace-text');
|
||||
}
|
||||
|
||||
const mouseTrap = this._mouseTrap;
|
||||
Object.keys(this.get('toolbar.shortcuts')).forEach(sc => mouseTrap.unbind(sc));
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
togglePreview="togglePreview"
|
||||
validation=validation
|
||||
loading=composer.loading
|
||||
forcePreview=forcePreview}}
|
||||
forcePreview=forcePreview
|
||||
composerEvents=true}}
|
||||
|
||||
<div class="composer-bottom-right">
|
||||
{{#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) {
|
||||
textarea.selectionStart = 5;
|
||||
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");
|
||||
|
||||
andThen(() => {
|
||||
|
@ -773,6 +797,7 @@ testCase("replace-text event", function(assert) {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
(() => {
|
||||
// Tests to check cursor/selection after replace-text event.
|
||||
const BEFORE = 'red green blue';
|
||||
|
@ -849,7 +874,7 @@ testCase("replace-text event", function(assert) {
|
|||
|
||||
for (let i = 0; i < CASES.length; 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);
|
||||
setSelection(textarea, CASE.before);
|
||||
andThen(() => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user