Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy-Paste Shortcuts Not Working #1199

Open
JoelProminic opened this issue Apr 6, 2023 · 32 comments
Open

Copy-Paste Shortcuts Not Working #1199

JoelProminic opened this issue Apr 6, 2023 · 32 comments

Comments

@JoelProminic
Copy link
Contributor

I have been noticing for a while that the copy and paste shortcuts (CMD-C and CMD-V on macOS) do not work in the text editors. I thought that this was only failing for certain file extensions or special cases, but when I did some tests today I found it was failing for everything. I tested these files:

Flex Desktop Project

  • .mxml
  • .xml
  • .as3proj

Java Gradle Project

  • build.gradle
  • .java

@rat-moonshine or @piotrzarzycki21, please take a look to see if this can be resolved easily on the Moonshine side. If this is an issue with the editor code, I would like to report this to Josh before he moves on to other big tasks.

@rat-moonshine
Copy link
Collaborator

rat-moonshine commented Apr 7, 2023

Unfortunately, the problem seems be unreliable itself. I couldn't able to reproduce the problem in my recent tests so far, on macOS. Copy/paste works as usual, although I myself seen the copy/paste problem in past.

@piotrzarzycki21
Copy link
Collaborator

I'm reproducing that problem quite often. It's been with us for a while and I cannot find consistent scenario when it is happen, but I will try from now on at least gather some scenarios to report here.

@rat-moonshine
Copy link
Collaborator

@joshtynjala do you think it's something at haxe-editor-API side, and you wants to look into (?)

@JoelProminic
Copy link
Contributor Author

The problem with this issue is that it has been difficult to reproduce consistently.

I was able to reproduce this with Domino Visual Editor (with development 3.3.4 build 3045), but I'm not sure this covers the issues that @rat-moonshine and @piotrzarzycki21 are seeing:

  1. Open an empty workspace and restart Moonshine
  2. Create/open a Java Gradle project (other projects may work)
  3. Test Copy-Paste in the .javaproj file - Works
  4. Create/Open a Domino Visual Editor project. Close any files that open for this project
  5. Test Copy-Paste in the .javaproj file - Works
  6. Open the .form file from nsfs/nsf-moonshine/odp/Forms/
  7. Test Copy-Paste in the .javaproj file - This fails
  8. Close the .form
  9. Test Copy-Paste in the .javaproj file - Works

Note that we have a pending update for copy-paste logic. However, this did not fix the above test case.

@joshtynjala
Copy link
Collaborator

I wonder if there's a conflict with focus between Flex and Feathers UI. Or maybe some other code in Moonshine is sometimes calling event.preventDefault() elsewhere, which may prevent the text editor from performing the copy/paste task.

I'll investigate.

@joshtynjala
Copy link
Collaborator

I was able to reproduce this with Domino Visual Editor (with development 3.3.4 build 3045)

I was able to reproduce by creating a Domino Visual Editor project and opening the .form file. While the .form file remains open, even if it is not the active editor, AIR is not dispatching Event.COPY to the TextEditor. The listener is simply never called when I press Cmd+C. However, I can see that the TextEditor has received stage focus because I can edit the file by typing on my keyboard. It's just the clipboard events that are missing. If I close the .form file, everything starts working again.

@joshtynjala
Copy link
Collaborator

joshtynjala commented May 11, 2023

With a little time following all KeyboardEvent.KEY_DOWN listeners for Cmd+C in the debugger, I determined the cause:

In UndoManagerVisualEditor, event.stopImmediatePropagation() and event.preventDefault() are called any time that event.ctrlKey is true and event.altKey is false.

https://github.com/Moonshine-IDE/Moonshine-IDE/blob/6c6086d/ide/MoonshineDESKTOPevolved/src/actionScripts/plugins/ui/editor/text/UndoManagerVisualEditor.as#L140-L157

Presumably, this listener should look more like this, so that other keys are allowed.

private function handleKeyDown(event:KeyboardEvent):void
{
	if ((event.keyCode == 22 || event.ctrlKey) && !event.altKey)
	{
		switch (event.keyCode)
		{
			case Keyboard.Y:		// Y
				event.stopImmediatePropagation();
				event.preventDefault();
				markEventAsPending('redo');
				break;
			case Keyboard.Z:		// Z
				event.stopImmediatePropagation();
				event.preventDefault();
				markEventAsPending('undo');
				break;
		}
	}
}

@rat-moonshine
Copy link
Collaborator

@piotrzarzycki21 can you think anything on the above line (?) since you knows better this part of the system.

@rat-moonshine
Copy link
Collaborator

rat-moonshine commented Jul 27, 2023

I updated the class-file that matches the suggestion from @joshtynjala .

However, for some reason I can't able to build Moonshine using Moonshine-IDE on macOS recently. There was no error but some warnings only. I still need to figure why this breaks. Meantime, I commit the UndoManagerVisualEditor.as so we can test a build from Bamboo.

@piotrzarzycki21
Copy link
Collaborator

I updated the class-file that matches the suggestion from @joshtynjala .

However, for some reason I can't able to build Moonshine using Moonshine-IDE on macOS recently. There was no error but some warnings only. I still need to figure why this breaks. Meantime, I commit the UndoManagerVisualEditor.as so we can test a build from Bamboo.

@rat-moonshine Now copy/paste by shortcuts doesn't work at all. Try to fix your local build and test with these changes.

@piotrzarzycki21
Copy link
Collaborator

However CMD+X does work.

@piotrzarzycki21
Copy link
Collaborator

Now it's started to work, so I'm not sure what has happened initially. I will observe behaviour on my Mac.

@piotrzarzycki21
Copy link
Collaborator

@rat-moonshine unfortunately that changes still didn't help. I do have this issue again - it's intermittent. How is going on your sight ?

@rat-moonshine
Copy link
Collaborator

So far I haven't noticed this during my tests.

@JoelProminic
Copy link
Contributor Author

@piotrzarzycki21 has still been seeing rare issues with the shortcuts for Royale and Haxe projects. I haven't noticed any problems with this in my recent work in Java projects.

@rat-moonshine
Copy link
Collaborator

The only scenario the copy/paste-shortcut still failing I see on macOS, is as follows:

  • Restart system
  • Open Moonshine-IDE, open any editor
  • Try copy/paste-shortcuts, they fail
  • Open any other application, copy some texts with shortcut
  • Return to Moonshine-IDE editor
  • Try to paste from system clipboard - paste works
  • Try to do more copy/paste job within Moonshine - they all works

From above behaviour, my assumption that until the system clipboard populated by some other application for first time, Moonshine not able to populate the clipboard by itself. For some reason the moonshine-feathersui-text-editor.TextEditor fails to populate the very first clipboard instance, on system.

To understand whether this problem is limited to TextEditor or not, I did following tests:

Test 1

  • Restart system
  • Open any AIR application that contains text-input, I chose Native AIR
  • Try to write something in login-like input, and copy/paste the content
  • This works without any problem

Test 2

  • Restart system
  • Open OpenFL application, I chose Native Haxe
  • Try to write something in login-view input, and copy/paste the texts
  • This worked also

Test 3

  • I inserted TextEditor normal text-editing view in an FeathersUI/OpenFL application
  • Keep the editor editable
  • Generate an .app file that populates the text-editor
  • Restart system
  • Open the .app file that generated in earlier step
  • Copy/paste do not works at all, surprisingly

Recently, @joshtynjala has enabled copy/paste shortcuts in TextEditor for #1229 , so this wondered me why test.3 fails to show ability of the same.

@rat-moonshine
Copy link
Collaborator

@joshtynjala please, check this, if you can provide your thought on Test.3, at some time.

I was wondering if Test.3 could give us some hint on continued problem with copy/paste, in Moonshine-IDE.

@joshtynjala
Copy link
Collaborator

I can reproduce Test 3 on Adobe AIR. It appears to be an AIR bug.

I confirmed that Event.COPY is correctly dispatched by AIR. My call to Clipboard.generalClipboard.setData() returns true, indicating that it should have worked correctly. However, a call to Clipboard.generalClipboard.getData() returns null instead of the text that I set.

If I switch to another app, copy some text, and then switch back to the AIR app and try to copy again, everything works correctly. Instead of null from Clipboard.generalClipboard.getData(), I get the string that I passed to Clipboard.generalClipboard.setData(), which is what should have happened the first time.

@rat-moonshine
Copy link
Collaborator

Do you think this clipboard bug could reason to the original issue here, @joshtynjala (?)

@joshtynjala
Copy link
Collaborator

Do you think this clipboard bug could reason to the original issue here, @joshtynjala (?)

Yes, that could certainly be the reason.

If it happens again, one way to test if this is the cause would be to switch to another app and copy some text. Then, switch back to Moonshine and try to copy/paste again.

@rat-moonshine
Copy link
Collaborator

rat-moonshine commented Jan 23, 2024

If it happens again, one way to test if this is the cause would be to switch to another app and copy some text. Then, switch back to Moonshine and try to copy/paste again.

Yes, I think I mentioned this at sometime to @JoelProminic , that if we copied some texts from another app, and paste into Moonshine-IDE editor, from then copy/paste works accordingly. So that behaviour match with yours.

@rat-moonshine
Copy link
Collaborator

rat-moonshine commented Jan 25, 2024

Last day @piotrzarzycki21 suggested to log an issue at Harman on Clipboard bug, but I just realised that we did tests already and it didn't shown as AIR specific bug, here in Test 1.

The bug seems to trigger when bridge between Haxe and AIR, so I don't think we have a strong reasoning to log this as an issue in AIR, to Harman.

@joshtynjala
Copy link
Collaborator

joshtynjala commented Jan 25, 2024

I can add the following code in an empty OpenFL project, and handling Event.COPY works correctly, so I guess it is either an issue with Feathers UI or moonshine-feathersui-text-editor.

var sprite:Sprite = new Sprite();
sprite.x = 20;
sprite.y = 20;
sprite.graphics.beginFill(0xff0000);
sprite.graphics.drawRect(0, 0, 200, 100);
sprite.graphics.endFill();
sprite.tabEnabled = true;
addChild(sprite);

// click the sprite and then press Ctrl/Cmd+C
stage.addEventListener(Event.COPY, function(event:Event):Void {
	trace(event);
	Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT, "hello");
	trace(Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT));
});

@joshtynjala
Copy link
Collaborator

joshtynjala commented Jan 25, 2024

Sorry, I was mistaken. I had forgotten the important step of restarting my system before launching the .app file. I can reproduce the issue in a plain Haxe/OpenFL project targeting AIR without Feathers UI or the TextEditor component.

In fact, I can also reproduce in a pure ActionScript 3.0 AIR project, using the following code (macOS 14.2.1, Apple Silicon M3):

package
{

	import flash.display.Sprite;
	import flash.events.Event;
	import flash.desktop.Clipboard;
	import flash.desktop.ClipboardFormats;
	import flash.text.TextField;

	public class ClipboardSetDataAfterRestartBug extends Sprite
	{
		public function ClipboardSetDataAfterRestartBug()
		{
			stage.nativeWindow.visible = true;
			
			var tf:TextField = new TextField();
			tf.width = stage.stageWidth;
			tf.height = stage.stageHeight;
			tf.tabEnabled = false;
			tf.mouseEnabled = false;
			tf.mouseWheelEnabled = false;
			addChild(tf);

			var sprite:Sprite = new Sprite();
			sprite.x = 20;
			sprite.y = 20;
			sprite.graphics.beginFill(0xff0000);
			sprite.graphics.drawRect(0, 0, 200, 100);
			sprite.graphics.endFill();
			sprite.tabEnabled = true;
			addChild(sprite);

			stage.addEventListener(Event.COPY, function(event:Event):void {
				tf.appendText(event + "\n");
				Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT, "hello");
				tf.appendText(Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT) + "\n");
			});
		}
	}
}

Steps:

  1. Compile AIR captive runtime .app file from code above.
  2. Restart system
  3. Launch the .app file
  4. Click on the red rectangle
  5. Press Cmd+C keyboard short cut.

The TextField will display something like this:

[Event(type="copy" bubbles=true cancelable=true eventPhase=3)]
null

It should display this instead:

[Event(type="copy" bubbles=true cancelable=true eventPhase=3)]
hello

So it is definitely an AIR bug.

@piotrzarzycki21
Copy link
Collaborator

@joshtynjala I build your example to Captive runtime using Air 50.2.2.6 ->
NewActionScriptDesktopProject.zip

I wasn't able to reproduce this issue on my macOS Sonoma 14.3.

Can you try @rat-moonshine as well with my app ?

@rat-moonshine
Copy link
Collaborator

rat-moonshine commented Jan 29, 2024

So it is definitely an AIR bug.

I confirm that I able to reproduce it while using AIR SDK v50.2 on macOS Ventura.

I surprise that somehow my similar AIR tests was passed earlier, that I described as Test 1 at here.

Anyway, I reported an issue to Harman AIR SDK repository with requisite example files, here - airsdk/Adobe-Runtime-Support#3039 .

@piotrzarzycki21
Copy link
Collaborator

So it is definitely an AIR bug.

I confirm that I able to reproduce it while using AIR SDK v50.2 on macOS Ventura.

I surprise that somehow my similar AIR tests was passed earlier, that I described as Test 1 at here.

Anyway, I reported an issue to Harman AIR SDK repository with requisite example files, here - airsdk/Adobe-Runtime-Support#3039 .

@rat-moonshine have you tried my build application ?

@piotrzarzycki21
Copy link
Collaborator

@rat-moonshine can you please specify exact version of Air in issue for Air support ? I will send them email directly cause we have payed support so they could look into it.

@rat-moonshine
Copy link
Collaborator

Ah! I was thinking about this earlier - if we has a paid-support since the license purchase of Harman AIR. That would be good if we can pass the issue with number, for a support.

I have updated AIR version in the issue.

@piotrzarzycki21
Copy link
Collaborator

Ah! I was thinking about this earlier - if we has a paid-support since the license purchase of Harman AIR. That would be good if we can pass the issue with number, for a support.

I have updated AIR version in the issue.

I just passed it. Thanks for the update.

@piotrzarzycki21
Copy link
Collaborator

Sounds like we will have in upcoming Air release fix for this :) - airsdk/Adobe-Runtime-Support#3039 (comment)

@JoelProminic
Copy link
Contributor Author

Since this is making progress, I added it to the current milestone. If it isn't ready by the time we want to do a release, we can bump it to a later release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Moonshine-IDE - Bug Fixing
  
Awaiting triage
Development

No branches or pull requests

4 participants