Skip to content

Compare/Replace selection or editor with clipboard #1862

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SougandhS
Copy link
Contributor

@SougandhS SougandhS commented May 8, 2025

This feature will allow users to compare either the selected text or the entire editor content against the current clipboard contents similar to other IDEs.


image


If users want to just compare just a selection in an editor, select the section and choose Compare with-> Clipboard
(I had changes copied..)

Selection.mp4

Selection2.mp4

If User want to compare entire Editor, either select all or select None and choose _Compare with-> Clipboard_
Entire.mp4

Copy link
Contributor

github-actions bot commented May 8, 2025

Test Results

 1 764 files  ±0   1 764 suites  ±0   1h 31m 34s ⏱️ - 14m 23s
 4 381 tests ±0   4 357 ✅ +1   24 💤 ±0  0 ❌  - 1 
13 143 runs  ±0  12 976 ✅ +1  167 💤 ±0  0 ❌  - 1 

Results for commit 73d7e06. ± Comparison against base commit 2e1acee.

♻️ This comment has been updated with latest results.

@SougandhS
Copy link
Contributor Author

Hi @iloveeclipse
Could you please check this when you have some time ?

@iloveeclipse
Copy link
Member

I'm biased here, since this feature is provided by AnyEdit Tools plugin since years:
https://marketplace.eclipse.org/content/anyedit-tools

@SougandhS
Copy link
Contributor Author

I'm biased here, since this feature is provided by AnyEdit Tools plugin since years: https://marketplace.eclipse.org/content/anyedit-tools

but having it built directly into Eclipse makes it easier and more consistent for users—no need to install or manage extra plugins just to do something that feels like it should be built-in

@vogella
Copy link
Contributor

vogella commented May 12, 2025

In my testing this does not reliable work.

For example in copy f.application from this file:

image

Now I select a java file and select Compare With -> Clipboard nothing happens.

image

@iloveeclipse
Copy link
Member

Why not let this feature be in AnyEdit plugin? It's tested, has more features etc.

@vogella
Copy link
Contributor

vogella commented May 12, 2025

Why not let this feature be in AnyEdit plugin? It's tested, has more features etc.

Having it in standard is desired for such a useful and core feature. Also I don't think every user has AnyEdit installed, for example I think I never did install it.

@iloveeclipse
Copy link
Member

I would expect then that this contribution would add same functionality AnyEdit provides for clipboard, means also context menus for files in Package Explorer, not just "Compare with..." but also "Replace with.." etc.

@SougandhS SougandhS force-pushed the CmpreSelcWithClip branch from bca7d6d to 0a132e9 Compare May 12, 2025 12:27
@SougandhS
Copy link
Contributor Author

In my testing this does not reliable work.
For example in copy f.application from this file:

This is fixed now

@SougandhS
Copy link
Contributor Author

I would expect then that this contribution would add same functionality AnyEdit provides for clipboard, means also context menus for files in Package Explorer, not just "Compare with..." but also "Replace with.." etc.

Sure. i'll add Replace with clipboard feature too 👍

@vogella
Copy link
Contributor

vogella commented May 12, 2025

I would expect then that this contribution would add same functionality AnyEdit provides for clipboard, means also context menus for files in Package Explorer, not just "Compare with..." but also "Replace with.." etc.

Sure. i'll add Replace with clipboard feature too 👍

Thanks. Next issue I see, is that it seems that I can also do this compare once. I tested my scenario above. After that I copied some source code from the compare editor and did the compare on another file. Nothing happens.

image

@SougandhS SougandhS force-pushed the CmpreSelcWithClip branch from 0a132e9 to 0096bed Compare May 13, 2025 11:17
@SougandhS
Copy link
Contributor Author

Next issue I see, is that it seems that I can also do this compare once. I tested my scenario above. After that I copied some source code from the compare editor and did the compare on another file. Nothing happens.

This is fixed now + Added replace with clipboard functionality + Compare/Replace from Project/Package exp context menu

Replace_1.mp4
Replace_2.mp4

@SougandhS SougandhS changed the title Compare selection or editor with clipboard Compare/Replace selection or editor with clipboard May 13, 2025
@vogella
Copy link
Contributor

vogella commented May 13, 2025

Calling compare on some files switching the project results in the following exception for me:

java.lang.NullPointerException: Cannot invoke "String.getBytes(java.nio.charset.Charset)" because "this.content" is null
at org.eclipse.compare.internal.ClipboardCompare$1ClipboardTypedElement.getContents(ClipboardCompare.java:148)
at org.eclipse.compare.internal.CompareUIPlugin.getContentType(CompareUIPlugin.java:1227)
at org.eclipse.compare.internal.CompareUIPlugin.getCommonType(CompareUIPlugin.java:1280)
at org.eclipse.compare.internal.CompareUIPlugin.findStructureViewerDescriptor(CompareUIPlugin.java:824)
at org.eclipse.compare.internal.CompareUIPlugin.findStructureViewer(CompareUIPlugin.java:867)
at org.eclipse.compare.CompareUI.findStructureViewer(CompareUI.java:321)
at org.eclipse.compare.CompareEditorInput.findStructureViewer(CompareEditorInput.java:893)
at org.eclipse.compare.internal.CompareStructureViewerSwitchingPane.getViewer(CompareStructureViewerSwitchingPane.java:87)
at org.eclipse.compare.CompareEditorInput$2.getViewer(CompareEditorInput.java:684)
at org.eclipse.compare.CompareViewerSwitchingPane.setInput(CompareViewerSwitchingPane.java:258)
at org.eclipse.compare.internal.CompareStructureViewerSwitchingPane.setInput(CompareStructureViewerSwitchingPane.java:140)
at org.eclipse.compare.CompareEditorInput.feedInput(CompareEditorInput.java:716)
at org.eclipse.compare.CompareEditorInput.createContents(CompareEditorInput.java:543)
at org.eclipse.compare.internal.CompareEditor.createCompareControl(CompareEditor.java:448)
at org.eclipse.compare.internal.CompareEditor.createPartControl(CompareEditor.java:400)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:160)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:96)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:367)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)

@SougandhS
Copy link
Contributor Author

Calling compare on some files switching the project results in the following exception for me:

java.lang.NullPointerException: Cannot invoke "String.getBytes(java.nio.charset.Charset)" because "this.content" is null at org.eclipse.compare.internal.ClipboardCompare$1ClipboardTypedElement.getContents(ClipboardCompare.java:148) at org.eclipse.compare.internal.CompareUIPlugin.getContentType(CompareUIPlugin.java:1227) at org.eclipse.compare.internal.CompareUIPlugin.getCommonType(CompareUIPlugin.java:1280) at org.eclipse.compare.internal.CompareUIPlugin.findStructureViewerDescriptor(CompareUIPlugin.java:824) at org.eclipse.compare.internal.CompareUIPlugin.findStructureViewer(CompareUIPlugin.java:867) at org.eclipse.compare.CompareUI.findStructureViewer(CompareUI.java:321) at org.eclipse.compare.CompareEditorInput.findStructureViewer(CompareEditorInput.java:893) at org.eclipse.compare.internal.CompareStructureViewerSwitchingPane.getViewer(CompareStructureViewerSwitchingPane.java:87) at org.eclipse.compare.CompareEditorInput$2.getViewer(CompareEditorInput.java:684) at org.eclipse.compare.CompareViewerSwitchingPane.setInput(CompareViewerSwitchingPane.java:258) at org.eclipse.compare.internal.CompareStructureViewerSwitchingPane.setInput(CompareStructureViewerSwitchingPane.java:140) at org.eclipse.compare.CompareEditorInput.feedInput(CompareEditorInput.java:716) at org.eclipse.compare.CompareEditorInput.createContents(CompareEditorInput.java:543) at org.eclipse.compare.internal.CompareEditor.createCompareControl(CompareEditor.java:448) at org.eclipse.compare.internal.CompareEditor.createPartControl(CompareEditor.java:400) at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:160) at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:96) at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:367) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.base/java.lang.reflect.Method.invoke(Method.java:580)

Strange. I'll provide null check for it

@SougandhS SougandhS force-pushed the CmpreSelcWithClip branch 2 times, most recently from 51a12e2 to b9af0a3 Compare May 13, 2025 12:47
@SougandhS
Copy link
Contributor Author

Calling compare on some files switching the project results in the following exception for me:
java.lang.NullPointerException: Cannot invoke "String.getBytes(java.nio.charset.Charset)" because "this.content" is null at

Reproduced and handled this now

@SougandhS SougandhS force-pushed the CmpreSelcWithClip branch from b9af0a3 to 5746f48 Compare May 14, 2025 00:24
@vogella vogella force-pushed the CmpreSelcWithClip branch from 5746f48 to b3f124c Compare May 16, 2025 06:37
@vogella
Copy link
Contributor

vogella commented May 16, 2025

Testing this again.

I don't think compare is correct for this example:

  • Create a text file, in my example lars.adoc with the following content:
lars
testing
compare
asdfklklsdf
  • Copy the last two lines into the clipbard.
  • Select the file and select compare with clipboard
  • Result:

image

@SougandhS please have a look

Allows users to compare or replace either the selected text or the
entire editor content against the clipboard content
@SougandhS SougandhS force-pushed the CmpreSelcWithClip branch from b3f124c to 73d7e06 Compare May 16, 2025 07:09
@SougandhS
Copy link
Contributor Author

@SougandhS please have a look

Thanks for this case. Its fixed now

bugfix.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants