insert-mode keybind: ^S - spoiler
This commit is contained in:
parent
ac49970879
commit
f4327d3b19
@ -426,7 +426,20 @@ keyModeInsert = (e) ->
|
||||
remove $ '#qr'
|
||||
e.preventDefault()
|
||||
else if e.ctrlKey and char is "S"
|
||||
console.log 'spoiler'
|
||||
ta = document.activeElement
|
||||
return unless ta.nodeName is 'TEXTAREA'
|
||||
|
||||
value = ta.value
|
||||
selStart = ta.selectionStart
|
||||
selEnd = ta.selectionEnd
|
||||
|
||||
valStart = value[0...selStart] + '[spoiler]'
|
||||
valMid = value[selStart...selEnd]
|
||||
valEnd = '[/spoiler]' + value[selEnd..]
|
||||
|
||||
ta.value = valStart + valMid + valEnd
|
||||
range = valStart.length + valMid.length
|
||||
ta.setSelectionRange range, range
|
||||
e.preventDefault()
|
||||
|
||||
keyModeNormal = (e) ->
|
||||
|
||||
16
4chan_x.js
16
4chan_x.js
@ -536,14 +536,26 @@
|
||||
}
|
||||
};
|
||||
keyModeInsert = function(e) {
|
||||
var char, kc;
|
||||
var char, kc, range, selEnd, selStart, ta, valEnd, valMid, valStart, value;
|
||||
kc = g.keyCode;
|
||||
char = g.char;
|
||||
if (kc === 27) {
|
||||
remove($('#qr'));
|
||||
return e.preventDefault();
|
||||
} else if (e.ctrlKey && char === "S") {
|
||||
console.log('spoiler');
|
||||
ta = document.activeElement;
|
||||
if (ta.nodeName !== 'TEXTAREA') {
|
||||
return;
|
||||
}
|
||||
value = ta.value;
|
||||
selStart = ta.selectionStart;
|
||||
selEnd = ta.selectionEnd;
|
||||
valStart = value.slice(0, selStart) + '[spoiler]';
|
||||
valMid = value.slice(selStart, selEnd);
|
||||
valEnd = '[/spoiler]' + value.slice(selEnd);
|
||||
ta.value = valStart + valMid + valEnd;
|
||||
range = valStart.length + valMid.length;
|
||||
ta.setSelectionRange(range, range);
|
||||
return e.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user