Dyalog / ride

Cross-platform IDE for Dyalog APL
https://dyalog.github.io/ride
MIT License
206 stars 32 forks source link

shortcuts to delete a character, a word, to eol #556

Open laynor opened 5 years ago

laynor commented 5 years ago

Describe the issue you are having

I'm currently using the below patch to be able to bind my PF keys to have more emacsy keybindings (would rather have vim, but that's another story).

diff --git a/src/km.js b/src/km.js
index b75daa8..407eddc 100644
--- a/src/km.js
+++ b/src/km.js
@@ -95,6 +95,11 @@
       }
     },
     DK(me) { me.trigger('editor', 'editor.action.deleteLines'); },
+    DI(me) { me.trigger('editor', 'deleteRight'); },
+    DWR(me) { me.trigger('editor', 'deleteWordRight'); },
+    FW(me) { me.trigger('editor', 'cursorWordEndRight'); },
+    BW(me) { me.trigger('editor', 'cursorWordStartLeft'); },
+    CES(me) { me.trigger('editor', 'cursorEndSelect'); },
     QCP(me) { me.trigger('editor', 'editor.action.quickCommand'); },
     QIT() { D.quit(); },
     LBR: D.prf.lbar.toggle,

In the prefs, I can use the added command in my PF keys to achieve the desired result. Is there a better way to do this?

Paste the contents of Help → About (Shift+F1)

IDE:
  Version: 4.3.1
  Platform: Linux x86_64
  Date: 2019-09-10 15:09:36 +0200
  Git commit: 385cff046aaaa5f6d13ac8c2be4aaad1802b8ecb
  Preferences:{
    "blockCursor":"1",
    "colourScheme":"almost-monochrome",
    "colourSchemes":"[{\"name\":\"almost-monochrome\",\"theme\":\"dark\",\"styles\":\"asgn=fg:ff0 com=fg:#5c497c,I cur=bc:f00 dfn2=fg:eb4 dfn3=fg:c79 dfn4=fg:cd0 dfn5=fg:#b974ce dfn=fg:a7b diam=fg:ff0 err=fg:#ce7171,bg:822,bgo:0.5,U fn=fg:#9075be idm=fg:0f0 glb=B kw=fg:#4d79aa lbl=U,bg:642,bgo:0.5 lnum=fg:b94,bg:010,bgo:0 mod=bg:7,bgo:0.5 mtch=fg:0,bg:0,bgo:0 norm=fg:#c0c0c0,bg:0,bgo:1 num=fg:#808080 op1=fg:#c0c0c0,B op2=fg:#ffffff,B sel=bg:048,bgo:0.5 semi=fg:8 sqbr=fg:8 srch=bg:b96,bgo:0.75,fg:0 str=fg:#6b5195 tc=bg:1,bgo:1 tcpe=bg:2,bgo:1 zld=fg:d9f,B scmd=fg:#55be6d,B ucmd=fg:f80,B vtip=bg:733,fg:ff0,bgo:1,bc:900 vtt=bc:f80 ca=bg:828282,bgo:1,fg:0f0 cm=bg:0,bgo:1,fg:0f0 cv=bg:f,bgo:1,fg:0 cvv=bg:0,bgo:1,fg:0ff ma=bg:828282,bgo:1,fg:0ff na=bg:828282,bgo:1,fg:f qor=bg:f00,bgo:1,fg:f dc=bg:3,bgo:1\"}]",
    "kbdLocale":"en_US",
    "keys":"{\"AO\":[\"Alt-;\"],\"BK\":[\"Alt-P\"],\"FD\":[\"Alt-N\"],\"LL\":[\"Ctrl-A\",\"Home\"],\"NEW\":[\"Ctrl-Shift-N\"],\"NX\":[\"F3\"],\"PRF\":[\"Ctrl-Alt-P\"],\"QCP\":[\"Ctrl-;\"],\"RD\":[\"Ctrl-R\"],\"RL\":[\"Ctrl-E\",\"End\"],\"SA\":[],\"SC\":[\"Ctrl-S\"],\"SI\":[\"Ctrl-Alt-K\"],\"WI\":[\"Ctrl-Alt-C\",\"Ctrl-PauseBreak\"],\"ZM\":[\"Alt-Enter\"],\"PF1\":[\"Ctrl-B\"],\"PF2\":[\"Ctrl-F\"],\"PF3\":[\"Ctrl-N\"],\"PF4\":[\"Ctrl-P\"],\"PF5\":[\"Ctrl-D\"],\"PF6\":[\"Ctrl-W\"],\"PF7\":[\"Ctrl-H\"],\"PF8\":[\"Ctrl-J\"],\"PF9\":[\"Alt-D\"],\"PF10\":[\"Alt-F\"],\"PF11\":[\"Alt-B\"],\"PF12\":[\"Ctrl-K\"]}",
    "minimapEnabled":"1",
    "otherExe":"/opt/mdyalog/17.1/64/unicode/mapl",
    "pfkeys":"[\"\",\"<LC>\",\"<RC>\",\"<DC>\",\"<UC>\",\"<DI>\",\"<EXP>\",\"<TIP>\",\"<VAL>\",\"<DWR>\",\"<FW>\",\"<BW>\",\"<CES><DI>\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]",
    "prefixKey":"j",
    "selectedExe":"/opt/mdyalog/17.1/64/unicode/mapl",
    "squiggleTips":"1",
    "wse":"1",
    "zoom":"2"
  }

Interpreter:
  Version: 17.1.36845
  Platform: Linux-64
  Edition: Unicode/64
  Date: Aug 15 2019 at 00:13:45
fourier commented 5 years ago

Just a comment, maybe this might be of your interest.

laynor commented 5 years ago

@fourier Thanks, I'm using dyalog-mode already, but couldn't get it to connect the dyalog session. This is probably not compatible with the unix version of Dyalog - it's using ⎕WC, which triggers value error on my side.

e9gille commented 5 years ago

Sorry for the late reply.

At the moment this is the only way to achieve what you want. RIDE doesn't expose all underlying features of the monaco editor, so you can only define shortcuts for commands that have been defined (as you have done in your patch).

MaxCan-Code commented 10 months ago

@laynor basic vim bindings is achievable with npm install monaco-vim (https://github.com/brijeshb42/monaco-vim) and

diff --git a/index.html b/index.html
index fed8ab3..bba7ecc 100644
--- a/index.html
+++ b/index.html
@@ -871,7 +871,10 @@
 <script>
   let dir = typeof __dirname !== 'undefined' ? `${__dirname}/` : '';
   amdRequire.config({
-    baseUrl: dir + 'node_modules/monaco-editor/min'
+    baseUrl: dir,
+    paths: {
+      'vs': 'node_modules/monaco-editor/min/vs',
+      'monaco-vim': 'node_modules/monaco-vim/dist/monaco-vim',
+    }
   });

   self.module = undefined;
diff --git a/src/km.js b/src/km.js
index 285101d..b76c7f5 100644
--- a/src/km.js
+++ b/src/km.js
@@ -162,6 +162,11 @@
             + 'please use "Connect..." instead.', 'Cannot Start New Session');
       }
     },
+    VIM(me) {
+      amdRequire(['vs/editor/editor.main', 'monaco-vim'], function(a, MonacoVim) {
+        vimMode = MonacoVim.initVimMode(me, document.createElement('div'));
+      });
+    },
+    MIV(me) { vimMode.dispose(); },
     DK(me) { me.trigger('editor', 'editor.action.deleteLines'); },
     QCP(me) { me.trigger('editor', 'editor.action.quickCommand'); },
     QIT() { D.quit(); },

But again is the question, is there a better way to do this? We can load extra code accordingly to https://github.com/Dyalog/ride/blob/master/sample-extensions/syntax-in-comments.js, but I'm not sure how we can add extra commands that way.