NorthwoodsSoftware / GoJS

JavaScript diagramming library for interactive flowcharts, org charts, design tools, planning tools, visual languages.
http://gojs.net
Other
7.7k stars 2.86k forks source link

Copying nodes in version 3.0.0 does not work #209

Closed Flareonn closed 4 months ago

Flareonn commented 4 months ago

You can compare it to the 2.3 version. Bug on version 3.0.0

All because of the announced change of InputEvent.key. Copying doesn't work on Russian layout exactly, I can't speak for others. It is reproduced only on Windows systems.

Why? I noticed that on Mac, when you click cmd, your .key ignores the keyboard layout and is always specified with an English letter, but not so on Windows

At the moment you can fix this behavior yourself with this code

    const isMac = navigator.platform.toUpperCase().indexOf('MAC')>=0;

    class CustomCommandHandler extends go.CommandHandler {
      public override doKeyDown(): void {
        const event = this.diagram.lastInput.event

        if(event instanceof KeyboardEvent) {
          const isCtrlPressed = isMac ? event.metaKey : event.ctrlKey
          if(isCtrlPressed) {
            if(event.code === 'KeyC' && this.canCopySelection()) {
              this.copySelection()

              return 
            }

            if(event.code === 'KeyV' && this.canPasteSelection()) {
              this.pasteSelection()

              return
            }
          }
        }

        return super.doKeyDown()
      }
    }

After that, use it when initializing go.Diagram

simonsarris commented 4 months ago

Reading about this now, I see the error. We'll make this more durable in 3.0.1

Out of curiosity, what are the Russian keys for copy and paste shortcuts? Are they just physically where C and V are on QWERTY style layouts? In other words the .key values are ц and в instead, presumably?

Flareonn commented 4 months ago

Reading about this now, I see the error. We'll make this more durable in 3.0.1

Out of curiosity, what are the Russian keys for copy and paste shortcuts? Are they just physically where C and V are on QWERTY style layouts? In other words the .key values are ц and в instead, presumably?

The keys are the same, just in their place: с for C and м for V.

image

simonsarris commented 4 months ago

if you try: https://gojs.net/temp/go301a.js

Does it work as you'd expect?

Live example: https://codepen.io/simonsarris/pen/OJGdZox?editors=1011

Flareonn commented 4 months ago

if you try: https://gojs.net/temp/go301a.js

Does it work as you'd expect?

Live example: https://codepen.io/simonsarris/pen/OJGdZox?editors=1011

Yes in the live example, it works

simonsarris commented 4 months ago

Ok, we'll release 3.0.1 in the coming days which will include this fix. Thank you for your help. I will close this issue when its released.

simonsarris commented 4 months ago

3.0.1 has been released and should fix this. Thank you for your help.

simonsarris commented 3 months ago

@Flareonn Sorry to bother you but we're considering further modifications to our key event code, and I want to be sure it works for cyrillic keyboard layouts. In my simulated testing it seems to work, but it would be good to get the testing of someone using the real keyboard before we release. Could you tell me if copy/paste and undo/redo work as you would expect in this sample?

https://codepen.io/simonsarris/pen/YzbVWqB?editors=1010