aboutsummaryrefslogtreecommitdiff
path: root/xP/public
diff options
context:
space:
mode:
Diffstat (limited to 'xP/public')
-rw-r--r--xP/public/xP.js47
1 files changed, 43 insertions, 4 deletions
diff --git a/xP/public/xP.js b/xP/public/xP.js
index aa2c39a..1cdb8b0 100644
--- a/xP/public/xP.js
+++ b/xP/public/xP.js
@@ -742,7 +742,7 @@ let Input = {
return true
},
- backward: (b, textarea) => {
+ backward: textarea => {
if (textarea.selectionStart !== textarea.selectionEnd)
return false
@@ -756,7 +756,7 @@ let Input = {
return true
},
- forward: (b, textarea) => {
+ forward: textarea => {
if (textarea.selectionStart !== textarea.selectionEnd)
return false
@@ -769,6 +769,42 @@ let Input = {
return true
},
+ modifyWord: (textarea, cb) => {
+ let start = textarea.selectionStart
+ let end = textarea.selectionEnd
+ if (start === end) {
+ let len = textarea.value.length
+ while (start < len && /\s/.test(textarea.value.charAt(start)))
+ start++;
+ end = start
+ while (end < len && !/\s/.test(textarea.value.charAt(end)))
+ end++;
+ }
+ if (start === end)
+ return false
+
+ const text = textarea.value, modified = cb(text.substring(start, end))
+ textarea.value = text.slice(0, start) + modified + text.slice(end)
+ end = start + modified.length
+ textarea.setSelectionRange(end, end)
+ return true
+ },
+
+ downcase: textarea => {
+ return Input.modifyWord(textarea, text => text.toLowerCase())
+ },
+
+ upcase: textarea => {
+ return Input.modifyWord(textarea, text => text.toUpperCase())
+ },
+
+ capitalize: textarea => {
+ return Input.modifyWord(textarea, text => {
+ const cps = Array.from(text.toLowerCase())
+ return cps[0].toUpperCase() + cps.slice(1).join('')
+ })
+ },
+
first: (b, textarea) => {
if (b.historyAt <= 0)
return false
@@ -823,8 +859,11 @@ let Input = {
if (hasShortcutModifiers(event)) {
handled = true
switch (event.key) {
- case 'b': success = Input.backward(b, textarea); break
- case 'f': success = Input.forward(b, textarea); break
+ case 'b': success = Input.backward(textarea); break
+ case 'f': success = Input.forward(textarea); break
+ case 'l': success = Input.downcase(textarea); break
+ case 'u': success = Input.upcase(textarea); break
+ case 'c': success = Input.capitalize(textarea); break
case '<': success = Input.first(b, textarea); break
case '>': success = Input.last(b, textarea); break
case 'p': success = Input.previous(b, textarea); break