Skip to content

Commit 16d3d17

Browse files
authored
Merge branch 'master' into issue/3764/formeditor
2 parents 62402e8 + b8d7d92 commit 16d3d17

File tree

12 files changed

+287
-7
lines changed

12 files changed

+287
-7
lines changed

bundles/org.eclipse.ui.editors/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.ui.editors; singleton:=true
5-
Bundle-Version: 3.21.0.qualifier
5+
Bundle-Version: 3.22.0.qualifier
66
Bundle-Activator: org.eclipse.ui.internal.editors.text.EditorsPlugin
77
Bundle-ActivationPolicy: lazy
88
Bundle-Vendor: %providerName

bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
import org.eclipse.jface.viewers.SelectionChangedEvent;
6969
import org.eclipse.jface.viewers.StructuredSelection;
7070
import org.eclipse.jface.viewers.TableViewer;
71+
import org.eclipse.jface.widgets.ButtonFactory;
72+
import org.eclipse.jface.widgets.WidgetFactory;
7173

7274
import org.eclipse.ui.IWorkbench;
7375
import org.eclipse.ui.IWorkbenchPreferencePage;
@@ -451,7 +453,9 @@ private OverlayPreferenceStore createDialogOverlayStore() {
451453
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_ENCLOSED_TABS));
452454
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_TRAILING_TABS));
453455
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_CARRIAGE_RETURN));
454-
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_LINE_FEED));
456+
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_LINE_FEED));
457+
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
458+
AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_ZW_CHARACTERS));
455459
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WHITESPACE_CHARACTER_ALPHA_VALUE));
456460

457461
OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
@@ -571,6 +575,15 @@ protected Control createDialogArea(Composite parent) {
571575
preference= new Preference(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_LINE_FEED, "", null); //$NON-NLS-1$
572576
addCheckBox(tabularComposite, preference, new BooleanDomain(), 0);
573577

578+
WidgetFactory.label(SWT.NONE).text(TextEditorMessages.TextEditorDefaultsPreferencePage_zwcharacters)
579+
.layoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)).create(tabularComposite);
580+
ButtonFactory checkboxFactory = WidgetFactory.button(SWT.CHECK)
581+
.supplyLayoutData(() -> new GridData(SWT.CENTER, SWT.CENTER, false, false)).enabled(false);
582+
checkboxFactory.create(tabularComposite);
583+
preference = new Preference(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_ZW_CHARACTERS, "", null); //$NON-NLS-1$
584+
addCheckBox(tabularComposite, preference, new BooleanDomain(), 0);
585+
checkboxFactory.create(tabularComposite);
586+
574587
Composite alphaComposite= new Composite(composite, SWT.NONE);
575588
layout= new GridLayout();
576589
layout.numColumns= 2;
@@ -809,6 +822,8 @@ private OverlayPreferenceStore createOverlayStore() {
809822
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_TRAILING_TABS));
810823
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_CARRIAGE_RETURN));
811824
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_LINE_FEED));
825+
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
826+
AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_ZW_CHARACTERS));
812827
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WHITESPACE_CHARACTER_ALPHA_VALUE));
813828

814829
OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];

bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ private TextEditorMessages() {
159159
public static String TextEditorDefaultsPreferencePage_ideographicSpace;
160160
public static String TextEditorDefaultsPreferencePage_leading;
161161
public static String TextEditorDefaultsPreferencePage_lineFeed;
162+
public static String TextEditorDefaultsPreferencePage_zwcharacters;
162163
public static String TextEditorDefaultsPreferencePage_range_indicator;
163164
public static String TextEditorDefaultsPreferencePage_smartHomeEnd;
164165
public static String TextEditorDefaultsPreferencePage_warn_if_derived;

bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ TextEditorDefaultsPreferencePage_enrichHover_onClick=Enrich on click
6161
TextEditorDefaultsPreferencePage_ideographicSpace=Ideographic space ( \u00b0 )
6262
TextEditorDefaultsPreferencePage_leading=Leading
6363
TextEditorDefaultsPreferencePage_lineFeed=Line Feed ( \u00b6 )
64+
TextEditorDefaultsPreferencePage_zwcharacters=Zero-Width Characters
6465
TextEditorDefaultsPreferencePage_range_indicator=Show &range indicator
6566
TextEditorDefaultsPreferencePage_warn_if_derived= War&n before editing a derived file
6667
TextEditorDefaultsPreferencePage_smartHomeEnd= &Smart caret positioning at line start and end

bundles/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditorPreferenceConstants.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ private AbstractDecoratedTextEditorPreferenceConstants() {
502502
* </p>
503503
*
504504
* <p>
505-
* The following preferences can be used for fine-grained configuration when enabled.
505+
* The following preferences can be used for fine-grained configuration when
506+
* enabled.
506507
* </p>
507508
* <ul>
508509
* <li>{@link #EDITOR_SHOW_LEADING_SPACES}</li>
@@ -516,6 +517,7 @@ private AbstractDecoratedTextEditorPreferenceConstants() {
516517
* <li>{@link #EDITOR_SHOW_TRAILING_TABS}</li>
517518
* <li>{@link #EDITOR_SHOW_CARRIAGE_RETURN}</li>
518519
* <li>{@link #EDITOR_SHOW_LINE_FEED}</li>
520+
* <li>{@link #EDITOR_SHOW_ZW_CHARACTERS}</li>
519521
* <li>{@link #EDITOR_WHITESPACE_CHARACTER_ALPHA_VALUE}</li>
520522
* </ul>
521523
*
@@ -647,6 +649,18 @@ private AbstractDecoratedTextEditorPreferenceConstants() {
647649
*/
648650
public static final String EDITOR_SHOW_LINE_FEED= AbstractTextEditor.PREFERENCE_SHOW_LINE_FEED;
649651

652+
/**
653+
* A named preference that controls the display of zero-width characters like
654+
* zero-width space. The value is used only if the value of
655+
* {@link #EDITOR_SHOW_WHITESPACE_CHARACTERS} is <code>true</code>.
656+
* <p>
657+
* Value is of type <code>Boolean</code>.
658+
* </p>
659+
*
660+
* @since 3.22
661+
*/
662+
public static final String EDITOR_SHOW_ZW_CHARACTERS = AbstractTextEditor.PREFERENCE_SHOW_ZW_CHARACTERS;
663+
650664
/**
651665
* A named preference that controls the alpha value of whitespace characters. The value is used
652666
* only if the value of {@link #EDITOR_SHOW_WHITESPACE_CHARACTERS} is <code>true</code>.
@@ -858,6 +872,7 @@ public static void initializeDefaultValues(IPreferenceStore store) {
858872
store.setDefault(EDITOR_SHOW_TRAILING_TABS, true);
859873
store.setDefault(EDITOR_SHOW_CARRIAGE_RETURN, true);
860874
store.setDefault(EDITOR_SHOW_LINE_FEED, true);
875+
store.setDefault(EDITOR_SHOW_ZW_CHARACTERS, true);
861876
store.setDefault(EDITOR_WHITESPACE_CHARACTER_ALPHA_VALUE, 80);
862877

863878
store.setDefault(EDITOR_TEXT_DRAG_AND_DROP_ENABLED, true);

bundles/org.eclipse.ui.workbench.texteditor/.settings/.api_filters

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<component id="org.eclipse.ui.workbench.texteditor" version="2">
3+
<resource path="src/org/eclipse/ui/texteditor/AbstractTextEditor.java" type="org.eclipse.ui.texteditor.AbstractTextEditor">
4+
<filter id="336658481">
5+
<message_arguments>
6+
<message_argument value="org.eclipse.ui.texteditor.AbstractTextEditor"/>
7+
<message_argument value="PREFERENCE_SHOW_ZW_CHARACTERS"/>
8+
</message_arguments>
9+
</filter>
10+
</resource>
311
<resource path="src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java" type="org.eclipse.ui.texteditor.ITextEditorActionConstants">
412
<filter id="571473929">
513
<message_arguments>

bundles/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.ui.workbench.texteditor; singleton:=true
5-
Bundle-Version: 3.20.0.qualifier
5+
Bundle-Version: 3.20.100.qualifier
66
Bundle-Activator: org.eclipse.ui.internal.texteditor.TextEditorPlugin
77
Bundle-ActivationPolicy: lazy
88
Bundle-Vendor: %providerName

bundles/org.eclipse.ui.workbench.texteditor/plugin.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,5 @@ blockSelectionModeFont.label= Text Editor Block Selection Font
215215
blockSelectionModeFont.description= The block selection mode font is used by text editors in block (column) mode. A monospace font should be used.
216216

217217
MinimapView.name=Minimap
218+
219+
CodeMining.show.ZWSP=Show ZWSP (Zero-Width Space)

bundles/org.eclipse.ui.workbench.texteditor/plugin.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,5 +1491,13 @@
14911491
visible="false">
14921492
</view>
14931493
</perspectiveExtension>
1494-
</extension>
1494+
</extension>
1495+
<extension
1496+
point="org.eclipse.ui.workbench.texteditor.codeMiningProviders">
1497+
<codeMiningProvider
1498+
class="org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMiningProvider"
1499+
id="org.eclipse.test.codemining.zswpProvider"
1500+
label="%CodeMining.show.ZWSP">
1501+
</codeMiningProvider>
1502+
</extension>
14951503
</plugin>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 SAP S.E. and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* SAP S.E. - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.ui.internal.texteditor.codemining;
15+
16+
import org.eclipse.swt.SWT;
17+
import org.eclipse.swt.custom.StyleRange;
18+
import org.eclipse.swt.custom.StyledText;
19+
import org.eclipse.swt.graphics.Color;
20+
import org.eclipse.swt.graphics.GC;
21+
import org.eclipse.swt.graphics.Point;
22+
23+
import org.eclipse.jface.preference.IPreferenceStore;
24+
25+
import org.eclipse.jface.text.Position;
26+
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
27+
import org.eclipse.jface.text.codemining.LineContentCodeMining;
28+
29+
import org.eclipse.ui.texteditor.AbstractTextEditor;
30+
31+
/**
32+
* A code mining that draws zero-width characters (like zero-width spaces) as
33+
* line content code minings.
34+
*
35+
* @see ZeroWidthCharactersLineContentCodeMiningProvider
36+
*/
37+
class ZeroWidthCharactersLineContentCodeMining extends LineContentCodeMining {
38+
39+
private static final String ZW_CHARACTERS_MINING = "ZWSP"; //$NON-NLS-1$
40+
private final IPreferenceStore store;
41+
private final int offset;
42+
43+
public ZeroWidthCharactersLineContentCodeMining(int offset, ICodeMiningProvider provider, IPreferenceStore store) {
44+
super(new Position(offset, 1), false, provider);
45+
this.store = store;
46+
this.offset = offset;
47+
}
48+
49+
@Override
50+
public boolean isResolved() {
51+
return true;
52+
}
53+
54+
@Override
55+
public String getLabel() {
56+
return ZW_CHARACTERS_MINING;
57+
}
58+
59+
@Override
60+
public Point draw(GC gc, StyledText textWidget, Color color, int x, int y) {
61+
int oldAlpha = -1;
62+
boolean isAdvancedGraphicsPresent = gc.getAdvanced();
63+
if (isAdvancedGraphicsPresent) {
64+
int alpha = store.getInt(AbstractTextEditor.PREFERENCE_WHITESPACE_CHARACTER_ALPHA_VALUE);
65+
oldAlpha = gc.getAlpha();
66+
gc.setAlpha(alpha);
67+
}
68+
try {
69+
gc.setForeground(getColor(textWidget));
70+
Point point = super.draw(gc, textWidget, color, x, y);
71+
gc.setForeground(color);
72+
return point;
73+
} finally {
74+
if (oldAlpha != -1) {
75+
gc.setAlpha(oldAlpha);
76+
}
77+
}
78+
}
79+
80+
private Color getColor(StyledText textWidget) {
81+
int off = offset - 1;
82+
Color fg;
83+
boolean isFullSelectionStyle = (textWidget.getStyle() & SWT.FULL_SELECTION) != SWT.NONE;
84+
if (!textWidget.getBlockSelection() && isFullSelectionStyle && isOffsetSelected(textWidget, off)) {
85+
fg = textWidget.getSelectionForeground();
86+
} else {
87+
if (off < 0 || off >= textWidget.getCharCount()) {
88+
fg = textWidget.getForeground();
89+
} else {
90+
StyleRange styleRange = textWidget.getStyleRangeAtOffset(off);
91+
if (styleRange == null || styleRange.foreground == null) {
92+
fg = textWidget.getForeground();
93+
} else {
94+
fg = styleRange.foreground;
95+
}
96+
}
97+
}
98+
return fg;
99+
}
100+
101+
private static final boolean isOffsetSelected(StyledText widget, int offset) {
102+
Point selection = widget.getSelection();
103+
return offset >= selection.x && offset < selection.y;
104+
}
105+
}

0 commit comments

Comments
 (0)