rename selectedText

pull/7748/head
Guilherme Gazzo 8 years ago
parent 890ccb6100
commit 22d38ed268
  1. 4
      packages/rocketchat-lib/client/lib/openRoom.js
  2. 10
      packages/rocketchat-ui-message/client/messageBox.js

@ -70,11 +70,9 @@ function openRoom(type, name) {
RoomManager.updateMentionsMarksOfRoom(type + name);
Meteor.setTimeout(() => readMessage.readNow(), 2000);
// KonchatNotification.removeRoomNotification(params._id)
if (Meteor.Device.isDesktop() && window.chatMessages && window.chatMessages[room._id] != null) {
setTimeout(() => $('.message-form .input-message').focus(), 100);
setTimeout(() => window.chatMessages[room._id].input.focus(), 100);
}
// update user's room subscription
const sub = ChatSubscription.findOne({rid: room._id});
if (sub && sub.open === false) {

@ -24,7 +24,7 @@ function applyMd(e, t) {
const box = t.find('.js-input-message');
const {selectionEnd = box.value.length, selectionStart = 0} = box;
const initText = box.value.slice(0, selectionStart);
const text = box.value.slice(selectionStart, selectionEnd);
const selectedText = box.value.slice(selectionStart, selectionEnd);
const finalText = box.value.slice(selectionEnd, box.value.length);
const [btn] = t.findAll(`.js-md[aria-label=${ this.label }]`);
@ -34,19 +34,19 @@ function applyMd(e, t) {
btn.classList.remove('active');
}, 100);
}
box.focus();
/*
get text
apply pattern
restore selection
*/
box.focus();
if (document.execCommand) {
document.execCommand('insertText', false, this.pattern.replace('{{text}}', text));
document.execCommand('insertText', false, this.pattern.replace('{{text}}', selectedText));
} else {
box.value = initText + this.pattern.replace('{{text}}', text) + finalText;
box.value = initText + this.pattern.replace('{{text}}', selectedText) + finalText;
}
box.selectionStart = selectionStart + this.pattern.indexOf('{{text}}');
box.selectionEnd = box.selectionStart + text.length;
box.selectionEnd = box.selectionStart + selectedText.length;
$(box).change();
}

Loading…
Cancel
Save