dokuwiki-plugin-prosemirror icon indicating copy to clipboard operation
dokuwiki-plugin-prosemirror copied to clipboard

keymap: change to support bold and italic keyboard shortcuts.

Open gyger opened this issue 1 year ago • 10 comments

This adds the function to use CTRL + B and CTRL + I to toggle between bold and italic.

gyger avatar May 06 '24 08:05 gyger

Together with PR https://github.com/cosmocode/dokuwiki-plugin-prosemirror/pull/203 they solve #122.

If you want I can also merge the two pull requests into one. We could also add other commands easily.

As an inspiration from the sample file (https://github.com/ProseMirror/prosemirror-example-setup/blob/master/src/keymap.ts) the following shortcuts are implemented (Dont think we need all, just as inspiration).

  • Mod-b for toggling strong
  • Mod-i for toggling emphasis
  • Mod-` for toggling code font
  • Ctrl-Shift-0 for making the current textblock a paragraph
  • Ctrl-Shift-1 to Ctrl-Shift-Digit6 for making the current textblock a heading of the corresponding level
  • Ctrl-Shift-Backslash to make the current textblock a code block
  • Ctrl-Shift-8 to wrap the selection in an ordered list
  • Ctrl-Shift-9 to wrap the selection in a bullet list
  • Ctrl-> to wrap the selection in a block quote
  • Enter to split a non-empty textblock in a list item while atnthe same time splitting the list item
  • Mod-Enter to insert a hard break
  • Mod-_ to insert a horizontal rule
  • Backspace to undo an input rule
  • Alt-ArrowUp to joinUp
  • Alt-ArrowDown to joinDown
  • Mod-BracketLeft to lift
  • Escape to selectParentNode

gyger avatar May 06 '24 08:05 gyger

I'm not a mac user, how does this map to macos and does it make sense there?

splitbrain avatar May 06 '24 10:05 splitbrain

I am neither, but according to documentation Mod- matches to CTRL on Win/Lin and Command on Mac.

Only italic and bold is implemented in this pull request, the test is just a list from the example implementation.

gyger avatar May 06 '24 16:05 gyger

Is this only working with a special browser in windows 10? I tried with edge and firefox. I copied the code from https://github.com/cosmocode/dokuwiki-plugin-prosemirror/pull/204/files to /var/www/html/dokuwiki/lib/plugins/prosemirror/script/plugins/Keymap/keymap.js ... but nothing happened. Ctrl+z is the only working short-cut. Is there something left to do ... or ist the code only working on a special OS or browser? ... or is it not realy implemented in the currently downloadable "build"?

StefanP74 avatar Jul 25 '24 07:07 StefanP74

@StefanP74 it's been a while since I applied this PR to my installation (a shame it's not been merged yet :cry:). If I remember correctly this code ends up in bundle.js after building. I thought it would be enough to yarn build this branch and replace bundle.js, but what did work for me at the end was:

  • Clone https://github.com/gyger/dokuwiki-plugin-prosemirror/
  • Checkout the fix-shortcutsformat branch
  • Run yarn install
  • Run yarn build
  • Copy the whole directory to the lib/plugins/prosemirror directory of your dokuwiki

pgschk avatar Jul 25 '24 07:07 pgschk

Hello,

what i did:

  • apt install yarnpkg
  • ln -s /usr/bin/yarnpkg /usr/bin/yarn
  • cd ~
  • wget https://github.com/gyger/dokuwiki-plugin-prosemirror/archive/refs/heads/master.zip
  • unzip ./master.zip
  • wget https://github.com/gyger/dokuwiki-plugin-prosemirror/archive/refs/heads/fix-shortcutsformat.zip
  • unzip ./fix-shortcutsformat.zip
  • wget https://github.com/gyger/dokuwiki-plugin-prosemirror/archive/refs/heads/fix-hardbreak.zip
  • unzip ./fix-hardbreak.zip
  • copy ./dokuwiki-plugin-prosemirror-fix-shortcutsformat/* to ./dokuwiki-plugin-prosemirror-master (replace all)
  • copy ./dokuwiki-plugin-prosemirror-fix-hardbreak/* to ./dokuwiki-plugin-prosemirror-master (replace all)
  • cd ./dokuwiki-plugin-prosemirror-master
  • yarn
  • yarn build
  • copy ./dokuwiki-plugin-prosemirror-master to /var/www/html/dokuwiki/lib/plugins/prosemirror (replace all)
  • replace rights of dirs and files in /var/www/html/dokuwiki/lib/plugins/prosemirror/* (www-data)

Ther are some warnings while running yarn build but no errors. So I tried it again to do Shift+Enter in dokuwiki at visual editor… but still not working ☹

Should it work with above steps? Did I something wrong?

Thx for your help.

StefanP74 avatar Jul 25 '24 09:07 StefanP74

@StefanP74 I can't test your approache, but if you are working directly on the system the easiest approach would be:

  • Uninstall prosemirror plugin through dokuwiki
  • cd /var/www/html/dokuwiki/lib/plugins/
  • git clone -b fix-shortcutsformat https://github.com/gyger/dokuwiki-plugin-prosemirror/ prosemirror
  • cd prosemirror
  • yarn install
  • yarn build

Afterwards make sure to refresh the dokuwiki page in your browser, ideally clearing cache, and try a different browser, to make sure you are not experiencing a cached javascript.

pgschk avatar Jul 25 '24 10:07 pgschk

Hallo,

yarn build ….. …. ERROR in ./script/plugins/Keymap/keymap.js Module Error (from ./node_modules/eslint-loader/index.js):

/var/www/html/dokuwiki/lib/plugins/prosemirror/script/plugins/Keymap/keymap.js 4:32 error 'exitCode' is defined but never used no-unused-vars

✖ 1 problem (1 error, 0 warnings)

@ ./script/main.js 17:14-48 error Command failed with exit code 2.

StefanP74 avatar Jul 25 '24 11:07 StefanP74

@StefanP74 You're right, this branch does not build on it's own, it is dependend on #203.

I failed to mention yarn install, in case you did not run it before yarn build, but I think you did.

You need to actually apply both changes, #203 and #204:

  • Uninstall prosemirror plugin through dokuwiki
  • cd /var/www/html/dokuwiki/lib/plugins/
  • git clone -b fix-shortcutsformat https://github.com/gyger/dokuwiki-plugin-prosemirror/ prosemirror
  • cd prosemirror
  • git merge -X ours origin/fix-hardbreak
  • yarn install
  • yarn build

Afterwards make sure to refresh the dokuwiki page in your browser, ideally clearing cache, and try a different browser, to make sure you are not experiencing a cached javascript.

@gyger I think you need to remove exitCode from line 4 for this PR, as it is only used by PR #203.

pgschk avatar Jul 25 '24 14:07 pgschk

Hello,

YESS!! It’s working now. 🙂 Thank you very much for your help. Prosemirror now works perfectly with Shift+Enter.

We are very happy about this well-functioning and simple to use WYSIWYG editor... as ckgedit does not do its job particularly well due to instability and extreme problems with ....

Don’t know you know it, … but this is an example what happens with ckgedit:

for %%f in ("%folder%\*") do ( set filename=%%~nxf set newname=%timestamp%_!filename! ren "%%f" "!newname!" )

... and this is what it becomes after saving:

for f in ("%folder%\*") do (

set filename=

~nxf set newname=%timestamp%_!filename! ren "f" "!newname!" )

And there’s no way to disable that code-chaos from my side. Prosemirror can handle this perfectly without any code transformation inside -tag. Perfect!

I will say thank you to all developers of prosemirror for that fantastic dokuwiki-plugin. 👍👍

Best regards

Stefan

StefanP74 avatar Jul 30 '24 08:07 StefanP74