Add quick code tags keybind.
This commit is contained in:
parent
d6ba19b2a8
commit
bccee036b2
@ -160,7 +160,8 @@
|
||||
openEmptyQR: ['I', 'Open QR without post number inserted'],
|
||||
openOptions: ['ctrl+o', 'Open Options'],
|
||||
close: ['Esc', 'Close Options or QR'],
|
||||
spoiler: ['ctrl+s', 'Quick spoiler'],
|
||||
spoiler: ['ctrl+s', 'Quick spoiler tags'],
|
||||
code: ['alt+c', 'Quick code tags'],
|
||||
submit: ['alt+s', 'Submit post'],
|
||||
watch: ['w', 'Watch thread'],
|
||||
update: ['u', 'Update now'],
|
||||
@ -1023,7 +1024,7 @@
|
||||
return $.on(d, 'keydown', Keybinds.keydown);
|
||||
},
|
||||
keydown: function(e) {
|
||||
var key, link, o, range, selEnd, selStart, ta, thread, value;
|
||||
var key, link, o, ta, thread;
|
||||
if (!(key = Keybinds.keyCode(e)) || /TEXTAREA|INPUT/.test(e.target.nodeName) && !(e.altKey || e.ctrlKey || e.keyCode === 27)) {
|
||||
return;
|
||||
}
|
||||
@ -1057,12 +1058,14 @@
|
||||
if (ta.nodeName !== 'TEXTAREA') {
|
||||
return;
|
||||
}
|
||||
value = ta.value;
|
||||
selStart = ta.selectionStart;
|
||||
selEnd = ta.selectionEnd;
|
||||
ta.value = value.slice(0, selStart) + '[spoiler]' + value.slice(selStart, selEnd) + '[/spoiler]' + value.slice(selEnd);
|
||||
range = 9 + selEnd;
|
||||
ta.setSelectionRange(range, range);
|
||||
Keybinds.tags('spoiler', ta);
|
||||
break;
|
||||
case Conf.code:
|
||||
ta = e.target;
|
||||
if (ta.nodeName !== 'TEXTAREA') {
|
||||
return;
|
||||
}
|
||||
Keybinds.tags('code', ta);
|
||||
break;
|
||||
case Conf.watch:
|
||||
Watcher.toggle(thread);
|
||||
@ -1203,6 +1206,15 @@
|
||||
}
|
||||
return key;
|
||||
},
|
||||
tags: function(tag, ta) {
|
||||
var range, selEnd, selStart, value;
|
||||
value = ta.value;
|
||||
selStart = ta.selectionStart;
|
||||
selEnd = ta.selectionEnd;
|
||||
ta.value = value.slice(0, selStart) + ("[" + tag + "]") + value.slice(selStart, selEnd) + ("[/" + tag + "]") + value.slice(selEnd);
|
||||
range = ("[" + tag + "]").length + selEnd;
|
||||
return ta.setSelectionRange(range, range);
|
||||
},
|
||||
img: function(thread, all) {
|
||||
var thumb;
|
||||
if (all) {
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
master
|
||||
|
||||
- Mayhem
|
||||
Add quick [code] tags keybind (alt+c).
|
||||
|
||||
2.30.4
|
||||
- Mayhem
|
||||
Add /co/ and /k/ archive redirection.
|
||||
|
||||
@ -123,7 +123,8 @@ Config =
|
||||
openEmptyQR: ['I', 'Open QR without post number inserted']
|
||||
openOptions: ['ctrl+o', 'Open Options']
|
||||
close: ['Esc', 'Close Options or QR']
|
||||
spoiler: ['ctrl+s', 'Quick spoiler']
|
||||
spoiler: ['ctrl+s', 'Quick spoiler tags']
|
||||
code: ['alt+c', 'Quick code tags']
|
||||
submit: ['alt+s', 'Submit post']
|
||||
# Thread related
|
||||
watch: ['w', 'Watch thread']
|
||||
@ -801,19 +802,11 @@ Keybinds =
|
||||
when Conf.spoiler
|
||||
ta = e.target
|
||||
return if ta.nodeName isnt 'TEXTAREA'
|
||||
|
||||
value = ta.value
|
||||
selStart = ta.selectionStart
|
||||
selEnd = ta.selectionEnd
|
||||
|
||||
ta.value =
|
||||
value[...selStart] +
|
||||
'[spoiler]' + value[selStart...selEnd] + '[/spoiler]' +
|
||||
value[selEnd..]
|
||||
|
||||
range = 9 + selEnd
|
||||
# Move the caret to the end of the selection.
|
||||
ta.setSelectionRange range, range
|
||||
Keybinds.tags 'spoiler', ta
|
||||
when Conf.code
|
||||
ta = e.target
|
||||
return if ta.nodeName isnt 'TEXTAREA'
|
||||
Keybinds.tags 'code', ta
|
||||
# Thread related
|
||||
when Conf.watch
|
||||
Watcher.toggle thread
|
||||
@ -884,6 +877,20 @@ Keybinds =
|
||||
if e.ctrlKey then key = 'ctrl+' + key
|
||||
key
|
||||
|
||||
tags: (tag, ta) ->
|
||||
value = ta.value
|
||||
selStart = ta.selectionStart
|
||||
selEnd = ta.selectionEnd
|
||||
|
||||
ta.value =
|
||||
value[...selStart] +
|
||||
"[#{tag}]" + value[selStart...selEnd] + "[/#{tag}]" +
|
||||
value[selEnd..]
|
||||
|
||||
range = "[#{tag}]".length + selEnd
|
||||
# Move the caret to the end of the selection.
|
||||
ta.setSelectionRange range, range
|
||||
|
||||
img: (thread, all) ->
|
||||
if all
|
||||
$.id('imageExpand').click()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user