Move between title/post inputs with return and backspace keys

This commit is contained in:
Toby Zerner 2015-06-12 16:37:43 +09:30
parent 52ff2f25ba
commit 5c21efe09d

View File

@ -41,12 +41,32 @@ export default class DiscussionComposer extends ComposerBody {
if (empty) { $this.val(''); }
});
setTimeout(() => $(element).trigger('input'));
},
onkeydown: (e) => {
if (e.which === 13) { // return
e.preventDefault();
this.editor.setSelectionRange(0, 0);
}
m.redraw.strategy('none');
}
})));
return items;
}
onload(element) {
super.onload(element);
this.editor.$('textarea').keydown((e) => {
if (e.which === 8 && e.target.selectionStart == 0 && e.target.selectionEnd == 0) { // Backspace
e.preventDefault();
var title = this.$(':input:enabled:visible:first')[0];
title.focus();
title.selectionStart = title.selectionEnd = title.value.length;
}
});
}
preventExit() {
return (this.title() || this.content()) && !confirm(this.props.confirmExit);
}