This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 244752 - "Replace With Original Text" will revert to code with the last part missing
Summary: "Replace With Original Text" will revert to code with the last part missing
Status: REOPENED
Alias: None
Product: versioncontrol
Classification: Unclassified
Component: Code (show other bugs)
Version: 8.0
Hardware: PC Windows 7
: P4 normal (vote)
Assignee: Ondrej Vrabec
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-27 19:10 UTC by swpalmer
Modified: 2014-05-28 13:31 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
diff sidebar (37.89 KB, image/png)
2014-05-28 05:40 UTC, Ondrej Vrabec
Details

Note You need to log in before you can comment on or make changes to this bug.
Description swpalmer 2014-05-27 19:10:52 UTC
Product Version = NetBeans IDE 8.0 (Build 201403101706)
Operating System = Windows 7 version 6.1 running on amd64
Java; VM; Vendor = 1.8.0_05
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.5-b02

With code under Mercurial version control:

Starting with something like:

	private void bindContainerForVisibility(PropertyGroupUIStuff pgStuff) {
		if (pgStuff.panel instanceof TitledPane) {
			TitledPane tp = (TitledPane) pgStuff.panel;
			ObservableBooleanValue visibleCondition = null;
			Parent contentContainer = (Parent) tp.getContent();
			ObservableList<Node> content = contentContainer.getChildrenUnmodifiable();

			for (int i = 0; i < content.size(); i++) {
				Node n = content.get(i);
				if (n.getUserData() instanceof PropertyRowInfo) {
					PropertyRowInfo pri = (PropertyRowInfo) n.getUserData();
					if (visibleCondition == null) {
						visibleCondition = pri.visible;
					} else {
						visibleCondition = Bindings.or(visibleCondition, pri.visible);
					}
				}
			}
			tp.managedProperty().bind(tp.visibleProperty());
			if (visibleCondition != null) {
				tp.visibleProperty().bind(visibleCondition);
			}
		}
	}

Select the inside of the method body only (not the first and last lines, so the method still exists).
Comment it out with Ctrl-Shift-C.  That gives:

	private void bindContainerForVisibility(PropertyGroupUIStuff pgStuff) {
//		if (pgStuff.panel instanceof TitledPane) {
//			TitledPane tp = (TitledPane) pgStuff.panel;
//			ObservableBooleanValue visibleCondition = null;
//			Parent contentContainer = (Parent) tp.getContent();
//			ObservableList<Node> content = contentContainer.getChildrenUnmodifiable();
//
//			for (int i = 0; i < content.size(); i++) {
//				Node n = content.get(i);
//				if (n.getUserData() instanceof PropertyRowInfo) {
//					PropertyRowInfo pri = (PropertyRowInfo) n.getUserData();
//					if (visibleCondition == null) {
//						visibleCondition = pri.visible;
//					} else {
//						visibleCondition = Bindings.or(visibleCondition, pri.visible);
//					}
//				}
//			}
//			tp.managedProperty().bind(tp.visibleProperty());
//			if (visibleCondition != null) {
//				tp.visibleProperty().bind(visibleCondition);
//			}
//		}
	}

Now click on the blue bar in the gutter.  Note that the popup showing the old code has the last part of the code missing.  It only shows this:

		if (pgStuff.panel instanceof TitledPane) {
			TitledPane tp = (TitledPane) pgStuff.panel;
			ObservableBooleanValue visibleCondition = null;
			Parent contentContainer = (Parent) tp.getContent();
			ObservableList<Node> content = contentContainer.getChildrenUnmodifiable();

			for (int i = 0; i < content.size(); i++) {
				Node n = content.get(i);
				if (n.getUserData() instanceof PropertyRowInfo) {
					PropertyRowInfo pri = (PropertyRowInfo) n.getUserData();
					if (visibleCondition == null) {
						visibleCondition = pri.visible;
					} else {
						visibleCondition = Bindings.or(visibleCondition, pri.visible);


14 lines, even the tooltip on the blue bar says 14 lines... not the correct number of 22 lines.

If you select the arrow to "revert to original code" that is exactly what you get... a partial chunk of code

Mercurial executable path is set in the Options as C:\Program Files\TortoiseHg\ which points to 
Mercurial Distributed SCM (version 3.0+3)
From TortoiseHg 3.0
Comment 1 Ondrej Vrabec 2014-05-28 05:40:03 UTC
Created attachment 147476 [details]
diff sidebar
Comment 2 Ondrej Vrabec 2014-05-28 05:43:37 UTC
i'm getting the same, see the screenshot. But in that case there are actually two diff chunks (notice the pink triangle at the bottom), you must of course revert both of them.
Happens when Tools -> Options -> Misc -> Diff | Internal Diff and Ignore Leading and Trailing WS is selected.
So simply:
- either turn off the option in Options and reopen the file
- or make sure you revert both the diff chunks

Or could it be that you cannot see two diffs as opposed to the screenshot?
Comment 3 swpalmer 2014-05-28 13:27:01 UTC
I do see what is happening now and it is very non-intuitive.  I think this should still be addressed, but at a lower priority.

The pink triangle is shown outside of the method body below the closing brace.  It may be doing something that is technically correct according to the diff algorithm, but it is not doing the right thing in terms of UI.

After restoring both blocks you end up with code where the indentation of the braces is completely wrong.  You do NOT get back to where you were before!

This is what I get after reverting both changes - the blue bar and the pink triangle:

	private void bindContainerForVisibility(PropertyGroupUIStuff pgStuff) {
		if (pgStuff.panel instanceof TitledPane) {
			TitledPane tp = (TitledPane) pgStuff.panel;
			ObservableBooleanValue visibleCondition = null;
			Parent contentContainer = (Parent) tp.getContent();
			ObservableList<Node> content = contentContainer.getChildrenUnmodifiable();

			for (int i = 0; i < content.size(); i++) {
				Node n = content.get(i);
				if (n.getUserData() instanceof PropertyRowInfo) {
					PropertyRowInfo pri = (PropertyRowInfo) n.getUserData();
					if (visibleCondition == null) {
						visibleCondition = pri.visible;
					} else {
						visibleCondition = Bindings.or(visibleCondition, pri.visible);
	}
				}
			}
			tp.managedProperty().bind(tp.visibleProperty());
			if (visibleCondition != null) {
				tp.visibleProperty().bind(visibleCondition);
			}
		}
	}

See that closing brace in the middle?

 It just looks and feels wrong.  If it can be improved it should be improved.
Comment 4 swpalmer 2014-05-28 13:31:37 UTC
Changing to P4, since unselecting "Ignore Leading And Tailing White Space" avoids the issue.

I still think reverting both changesets implies that the state should be what it was prior to those changes, but perhaps I can be convinced otherwise.

Maybe the algorithm to ignore leading and trailing white space can be a little bit smarter, because it doesn't produce a good result in this case.