correct positioning when emoji is added

This commit is contained in:
Sam 2014-12-08 14:22:54 +11:00
parent 555b783864
commit 23163422e6
3 changed files with 24 additions and 6 deletions

View File

@ -75,12 +75,28 @@ export default DiscourseController.extend({
appendText: function(text, opts) {
var c = this.get('model');
if (c) { c.appendText(text, undefined , opts); }
if (c) {
var wmd = $('#wmd-input');
var position = opts.position === "cursor" ? wmd.caret() : wmd.val().length;
var caret = c.appendText(text, position, opts);
Em.run.next(function(){
Discourse.Utilities.setCaretPosition(wmd[0], caret);
});
}
},
appendBlockAtCursor: function(text) {
var c = this.get('model');
if (c) { c.appendText(text, $('#wmd-input').caret(), {block: true}); }
appendTextAtCursor: function(text, opts) {
opts = opts || {};
opts.position = "cursor";
this.appendText(text, opts);
},
appendBlockAtCursor: function(text, opts) {
opts = opts || {};
opts.position = "cursor";
opts.block = true;
this.appendText(text, opts);
},
categories: function() {

View File

@ -312,6 +312,8 @@ Discourse.Composer = Discourse.Model.extend({
}
this.set('reply', before + text + after);
return before.length + text.length;
},
togglePreview: function() {

View File

@ -33,7 +33,6 @@ var renderPage = Handlebars.compile(
var closeSelector = function(){
$('.emoji-modal, .emoji-modal-wrapper').remove();
$('body, textarea').off('keydown.emoji');
$('#wmd-input').focus();
};
var showSelector = function(){
@ -61,8 +60,9 @@ var showSelector = function(){
var composerController = Discourse.__container__.lookup('controller:composer');
$('.emoji-page a').click(function(){
composerController.appendText(":" + $(this).attr('title') + ":", {space: true});
composerController.appendTextAtCursor(":" + $(this).attr('title') + ":", {space: true});
closeSelector();
return false;
});
$('body, textarea').on('keydown.emoji', function(e){