mirror of
https://github.com/discourse/discourse.git
synced 2025-02-06 21:51:45 +08:00
FIX: Keyboard handling regression
This commit is contained in:
parent
0ede6b5ed6
commit
84a50a1260
|
@ -159,6 +159,7 @@ export default Ember.Component.extend({
|
||||||
insertLinkHidden: true,
|
insertLinkHidden: true,
|
||||||
link: '',
|
link: '',
|
||||||
lastSel: null,
|
lastSel: null,
|
||||||
|
_mouseTrap: null,
|
||||||
|
|
||||||
@computed('placeholder')
|
@computed('placeholder')
|
||||||
placeholderTranslated(placeholder) {
|
placeholderTranslated(placeholder) {
|
||||||
|
@ -172,10 +173,12 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
loadScript('defer/html-sanitizer-bundle').then(() => this.set('ready', true));
|
loadScript('defer/html-sanitizer-bundle').then(() => this.set('ready', true));
|
||||||
|
|
||||||
|
const mouseTrap = Mousetrap(this.$('.d-editor-input')[0]);
|
||||||
|
|
||||||
const shortcuts = this.get('toolbar.shortcuts');
|
const shortcuts = this.get('toolbar.shortcuts');
|
||||||
Ember.keys(shortcuts).forEach(sc => {
|
Ember.keys(shortcuts).forEach(sc => {
|
||||||
const button = shortcuts[sc];
|
const button = shortcuts[sc];
|
||||||
Mousetrap(this.$('.d-editor-input')[0]).bind(sc, () => {
|
mouseTrap.bind(sc, () => {
|
||||||
this.send(button.action, button);
|
this.send(button.action, button);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
@ -190,15 +193,16 @@ export default Ember.Component.extend({
|
||||||
this.appEvents.on('composer:insert-text', text => {
|
this.appEvents.on('composer:insert-text', text => {
|
||||||
this._addText(this._getSelected(), text);
|
this._addText(this._getSelected(), text);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this._mouseTrap = mouseTrap;
|
||||||
},
|
},
|
||||||
|
|
||||||
@on('willDestroyElement')
|
@on('willDestroyElement')
|
||||||
_shutDown() {
|
_shutDown() {
|
||||||
this.appEvents.off('composer:insert-text');
|
this.appEvents.off('composer:insert-text');
|
||||||
|
|
||||||
Ember.keys(this.get('toolbar.shortcuts')).forEach(sc => {
|
const mouseTrap = this._mouseTrap;
|
||||||
Mousetrap(this.$('.d-editor-input')[0]).unbind(sc);
|
Ember.keys(this.get('toolbar.shortcuts')).forEach(sc => mouseTrap.unbind(sc));
|
||||||
});
|
|
||||||
this.$('.d-editor-preview').off('click.preview');
|
this.$('.d-editor-preview').off('click.preview');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -374,8 +374,7 @@ export default {
|
||||||
if ((combo === 'ctrl+f' || combo === 'command+f') && element.id === 'search-term') {
|
if ((combo === 'ctrl+f' || combo === 'command+f') && element.id === 'search-term') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return oldStopCallback.call(this, e, element, combo, sequence);
|
||||||
return oldStopCallback(e, element, combo, sequence);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,6 +42,24 @@ test("Tests the Composer controls", () => {
|
||||||
ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good');
|
ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
// Testing keyboard events is tough!
|
||||||
|
const mac = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
||||||
|
const event = document.createEvent('Event');
|
||||||
|
event.initEvent('keydown', true, true);
|
||||||
|
event[mac ? 'metaKey' : 'ctrlKey'] = true;
|
||||||
|
event.keyCode = 66;
|
||||||
|
|
||||||
|
find('#reply-control .d-editor-input')[0].dispatchEvent(event);
|
||||||
|
});
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
const example = I18n.t(`composer.bold_text`);
|
||||||
|
equal(find('#reply-control .d-editor-input').val().trim(),
|
||||||
|
`this is the *content* of a post**${example}**`,
|
||||||
|
"it supports keyboard shortcuts");
|
||||||
|
});
|
||||||
|
|
||||||
click('#reply-control a.cancel');
|
click('#reply-control a.cancel');
|
||||||
andThen(() => {
|
andThen(() => {
|
||||||
ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
|
ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
|
||||||
|
|
|
@ -63,7 +63,6 @@ function testCase(title, testFunc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
testCase(`bold button with no selection`, function(assert, textarea) {
|
testCase(`bold button with no selection`, function(assert, textarea) {
|
||||||
console.log(textarea.selectionStart);
|
|
||||||
click(`button.bold`);
|
click(`button.bold`);
|
||||||
andThen(() => {
|
andThen(() => {
|
||||||
const example = I18n.t(`composer.bold_text`);
|
const example = I18n.t(`composer.bold_text`);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user