You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2020/12/13 20:55:18 UTC
[netbeans] 01/01: Revert "[NETBEANS-819] partial fix for cursor.
Text selection does't work"
This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a commit to branch revert-2509-NETBEANS-819
in repository https://gitbox.apache.org/repos/asf/netbeans.git
commit 4292453d4ec9ca5fb008257459ed1e6336a52b16
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Sun Dec 13 12:54:51 2020 -0800
Revert "[NETBEANS-819] partial fix for cursor. Text selection does't work"
This reverts commit e6a33460a464573082a8dbef5bc5c730ae154839.
---
.../org/netbeans/lib/terminalemulator/Line.java | 124 +++++++++++----------
.../lib/terminalemulator/MyFontMetrics.java | 28 ++---
.../src/org/netbeans/lib/terminalemulator/Sel.java | 22 ++--
.../org/netbeans/lib/terminalemulator/Term.java | 64 +++++------
4 files changed, 120 insertions(+), 118 deletions(-)
diff --git a/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Line.java b/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Line.java
index 5ca5052..609e9f0 100644
--- a/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Line.java
+++ b/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Line.java
@@ -32,16 +32,16 @@ final class Line {
private char buf[]; // actual characters
private int attr[]; // attributes (allocated on demand)
-
+
// SHOULD use shorts?
private int capacity; // == buf.length == attr.length
private int length; // how much of buf and attr is filled
-
-
+
+
public Line() {
reset();
}
-
+
public void reset() {
length = 0;
capacity = 32;
@@ -57,11 +57,11 @@ final class Line {
reset();
clearToEndFrom(term, 0, end, eraseAttr);
}
-
+
public int capacity() {
return capacity;
}
-
+
/**
* Number of characters in the line.
* charArray()[length()] is where the cursor or newline would be.
@@ -70,11 +70,11 @@ final class Line {
public int length() {
return length;
}
-
+
public boolean hasAttributes() {
return attr != null;
}
-
+
private int glyphId;
public void setGlyphId(int glyphId) {
this.glyphId = glyphId;
@@ -82,7 +82,7 @@ final class Line {
public int getGlyphId() {
return glyphId;
}
-
+
private int backgroundColor;// Background color for the whole line
// This is independent of per-character
// rendition.
@@ -92,7 +92,7 @@ final class Line {
public int getBackgroundColor() {
return backgroundColor;
}
-
+
public void setWrapped(boolean wrapped) {
this.wrapped = wrapped;
}
@@ -101,9 +101,9 @@ final class Line {
}
// SHOULD collapse wrapped with about_to_wrap into a bitfield
private boolean wrapped;
-
-
-
+
+
+
public boolean setAboutToWrap(boolean about_to_wrap) {
boolean old_about_to_wrap = about_to_wrap;
this.about_to_wrap = about_to_wrap;
@@ -114,8 +114,8 @@ final class Line {
}
// Perhaps SHOULD have a state: normal, about-to-wrap, wrapped.
private boolean about_to_wrap;
-
-
+
+
/**
* Return true if we've already seen attributes for this line
* or 'a' is the first one, in which case we allocate the 'attr' array.
@@ -126,54 +126,54 @@ final class Line {
}
return attr != null;
}
-
-
+
+
public void accumulateInto(int bcol, int ecol, StringBuffer buf) {
buf.append(this.buf, bcol, ecol-bcol+1);
}
-
+
public char charAt(int col) {
return buf[col];
}
-
+
private void charAtPut(int col, char c) {
buf[col] = c;
}
-
+
@Override
public String toString() {
assert false;
return new String(buf);
}
-
+
public char[] getChars(char[] array) {
System.arraycopy(buf, 0, array, 0, length);
return array;
}
-
+
public int [] attrArray() {
return attr;
}
-
- public int stringWidth(MyFontMetrics metrics, int at) {
- return metrics.getFm().charsWidth(buf, 0, at);
- }
-
+
+
public byte width(MyFontMetrics metrics, int at) {
if (at >= capacity)
return 1;
return (byte) metrics.wcwidth(charAt(at));
}
-
+
/*
* Convert a cell column to a buffer column.
*/
public int cellToBuf(MyFontMetrics metrics, int target_col) {
if (metrics.isMultiCell()) {
int bc = 0;
+ int vc = 0;
for(;;) {
- int w = stringWidth(metrics, bc);
- if (w - 1 >= target_col) break;
+ int w = width(metrics, bc);
+ if (vc + w - 1 >= target_col)
+ break;
+ vc += w;
bc++;
}
return bc;
@@ -181,20 +181,24 @@ final class Line {
return target_col;
}
}
-
+
/*
* Convert a buffer column to a cell column.
*/
public int bufToCell(MyFontMetrics metrics, int target_col) {
if (metrics.isMultiCell()) {
- return stringWidth(metrics, target_col);
+ int vc = 0;
+ for (int bc = 0; bc < target_col; bc++) {
+ vc += width(metrics, bc);
+ }
+ return vc;
} else {
return target_col;
}
}
-
-
-
+
+
+
public StringBuffer stringBuffer() {
// only used for word finding
// Grrr, why don't we have: new StringBuffer(buf, 0, length);
@@ -205,35 +209,35 @@ final class Line {
StringBuffer sb = new StringBuffer(length);
return sb.append(buf, 0, length);
}
-
+
/*
* Ensure that we have at least 'min_capacity'.
*/
private void ensureCapacity(Term term, int min_capacity) {
-
+
term.noteColumn(this, min_capacity);
-
+
if (min_capacity <= capacity)
return; // nothing to do
-
+
// doubling
int new_capacity = (length+1) * 2;
if (new_capacity < 0)
new_capacity = Integer.MAX_VALUE;
else if (min_capacity > new_capacity)
new_capacity = min_capacity;
-
-
+
+
char new_buf[] = new char[new_capacity];
System.arraycopy(buf, 0, new_buf, 0, length);
buf = new_buf;
-
+
if (attr != null) {
int new_attr[] = new int[new_capacity];
System.arraycopy(attr, 0, new_attr, 0, length);
attr = new_attr;
}
-
+
capacity = new_capacity;
}
@@ -246,14 +250,14 @@ final class Line {
attr[col] = eraseAttr;
}
}
-
+
/**
* Insert character and attribute at 'column' and shift everything
* past 'column' right.
*/
public void insertCharAt(Term term, char c, int column, int a) {
int new_length = length + 1;
-
+
if (column >= length) {
new_length = column+1;
ensureCapacity(term, new_length);
@@ -264,16 +268,16 @@ final class Line {
if (haveAttributes(a))
System.arraycopy(attr, column, attr, column + 1, length - column);
}
-
+
term.checkForMultiCell(c);
-
+
charAtPut(column, c);
if (haveAttributes(a))
attr[column] = a;
-
+
length = new_length;
}
-
+
/*
* Generic addition and modification.
* Line will grow to accomodate column.
@@ -293,7 +297,7 @@ final class Line {
attr[column] = a;
}
}
-
+
public void deleteCharAt(int column) {
if (column < 0 || column >= length)
return;
@@ -306,7 +310,7 @@ final class Line {
// SHOULD move this up
length--;
}
-
+
public void clearToEndFrom(Term term, int from, int end, int eraseAttr) {
ensureCapacity(term, end+1);
fillGap(end, eraseAttr);
@@ -350,7 +354,7 @@ final class Line {
if (length < to+1)
length = to+1;
}
-
+
/*
* Used for selections
* If the ecol is past the actual line length a "\n" is appended.
@@ -361,10 +365,10 @@ final class Line {
System.out.println("Line.text(bcol " + bcol + " ecol " + ecol + ")"); // NOI18N
System.out.println("\tlength " + length); // NOI18N
*/
-
-
+
+
String newline = ""; // NOI18N
-
+
// This only happens for 'empty' lines below the cursor.
// Actually it also happens for 'empty' lines in the middle.
// See issue 31951 for example.
@@ -373,15 +377,15 @@ final class Line {
// This is in fact what xterm does.
// DtTerm doesn't allow selection of the 'empty' lines below the
// cursor, but that is issue 21577 and is not easy to solve.
-
+
if (length == 0)
return "\n"; // NOI18N
-
+
if (ecol >= length) {
// The -1 snuffs out the newline.
ecol = length-1;
newline = "\n"; // NOI18N
-
+
if (bcol >= length)
bcol = length-1;
}
@@ -391,14 +395,14 @@ final class Line {
}
return new String(buf, bcol, count) + newline;
}
-
+
public void setCharacterAttribute(int bcol, int ecol,
int value, boolean on) {
// HACK: value is the ANSI code, haveAttributes takes out own
// compact encoding, but it only checks for 0 so it's OK.
if (!haveAttributes(value))
return;
-
+
try {
if (on) {
for (int c = bcol; c <= ecol; c++)
diff --git a/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/MyFontMetrics.java b/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/MyFontMetrics.java
index 67a6ec2..2eececf 100644
--- a/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/MyFontMetrics.java
+++ b/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/MyFontMetrics.java
@@ -77,7 +77,7 @@ class MyFontMetrics {
*
* CacheFactory doles out WidthCaches.
*
- * These caches are 64Kb (Character.MAX_VALUE+1) and we don't really want
+ * These caches are 64Kb (Character.MAX_VALUE+1) and we don't really want
* Each interp to have it's own. So we share them in a map using FontMetrics
* as a key. Unfortunately stuff will accumulate in the map. A WeakHashMap
* is no good because the keys (FontMetrics) are usually alive. For all I
@@ -91,7 +91,7 @@ class MyFontMetrics {
* it's reference. To make the reference count go down CacheFactory.disposeBy()
* is used. And that is called from MyFontMetrics.finalize().
*
- * NOTE: The actual WidthCache's instances _will_ accumulate, but they are small and
+ * NOTE: The actual WidthCache's instances _will_ accumulate, but they are small and
* there are only so many font variations an app can go through. As I
* mentioned above using a WeakHashMap doesn't help much because WidthCache's
* are keyed by relatively persistent FontMetrics.
@@ -121,12 +121,12 @@ class MyFontMetrics {
}
- public MyFontMetrics(Component component) {
- this.cmp = component;
- width = getFm().charWidth('a');
- height = getFm().getHeight();
- ascent = getFm().getAscent();
- leading = getFm().getLeading();
+ public MyFontMetrics(Component component, Font font) {
+ fm = component.getFontMetrics(font);
+ width = fm.charWidth('a');
+ height = fm.getHeight();
+ ascent = fm.getAscent();
+ leading = fm.getLeading();
// HACK
// From all I can tell both xterm and DtTerm ignore the leading.
@@ -142,22 +142,18 @@ class MyFontMetrics {
height -= leading;
leading = 0;
- cwidth_cache = CacheFactory.cacheForFontMetrics(getFm());
- }
-
- public FontMetrics getFm() {
- return this.cmp.getFontMetrics(cmp.getFont());
+ cwidth_cache = CacheFactory.cacheForFontMetrics(fm);
}
@Override
protected void finalize() {
- CacheFactory.disposeBy(getFm());
+ CacheFactory.disposeBy(fm);
}
public int width;
public int height;
public int ascent;
public int leading;
- public Component cmp;
+ public FontMetrics fm;
private WidthCache cwidth_cache;
public boolean isMultiCell() {
@@ -173,7 +169,7 @@ class MyFontMetrics {
if (cell_width == 0) {
// width not cached yet so figure it out
- int pixel_width = getFm().charWidth(c);
+ int pixel_width = fm.charWidth(c);
if (pixel_width == width) {
cell_width = 1;
diff --git a/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Sel.java b/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Sel.java
index 0dd498c..cbe620f 100644
--- a/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Sel.java
+++ b/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Sel.java
@@ -98,17 +98,17 @@ class Sel implements ClipboardOwner {
// properties:
private Color color = new Color(204, 204, 255); // swing color
- void setColor(Color color) { this.color = color; }
- Color getColor() { return color; }
-
+ void setColor(Color color) { this.color = color; }
+ Color getColor() { return color; }
+
private Color xor_color = Color.white;
- void setXORColor(Color color) { xor_color = color; }
+ void setXORColor(Color color) { xor_color = color; }
Color getXORColor() { return xor_color; }
Sel(Term term, State state) {
this.term = term;
this.state = state;
- }
+ }
/**
* Adjust the selection against 'afirstline'.
@@ -210,7 +210,7 @@ class Sel implements ClipboardOwner {
sel_tracking = Sel.SEL_LINE;
old_sel_tracking = Sel.SEL_NONE;
}
-
+
public void select_line(Extent range) {
sel_origin = new Coord(range.begin);
sel_extent = new Coord(range.end);
@@ -321,7 +321,7 @@ class Sel implements ClipboardOwner {
*/
if (cancelHelp(true))
term.repaint(false);
- }
+ }
public String getSelection() {
@@ -344,7 +344,7 @@ class Sel implements ClipboardOwner {
}
/*
- * Helps decide what to do with the selection when a line is
+ * Helps decide what to do with the selection when a line is
* added, removed or cleared.
*/
int intersection(int line) {
@@ -393,18 +393,20 @@ class Sel implements ClipboardOwner {
begin = term.toViewCoord(begin);
end = term.toViewCoord(end);
-
+
//Hotfix for issue 40189
if (begin == null || end == null) {
return;
}
+ int lw; // width of last character in selection
Line l = term.buf().lineAt(row);
+ lw = l.width(term.metrics(), ecol);
Point pbegin = term.toPixel(begin);
Point pend = term.toPixel(end);
pend.y += term.metrics().height;
- pend.x += l.stringWidth(term.metrics(), ecol); // xterm actually doesn't do this
+ pend.x += term.metrics().width * lw; // xterm actually doesn't do this
Dimension dim = new Dimension(pend.x - pbegin.x,
pend.y - pbegin.y);
diff --git a/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Term.java b/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Term.java
index db58620..a0aac2d 100644
--- a/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Term.java
+++ b/ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Term.java
@@ -268,9 +268,9 @@ public class Term extends JComponent implements Accessible {
private Clipboard systemSelection = getToolkit().getSystemSelection();
private static final Color TRANSPARENT = new Color(0, 0, 0, 0);
- //
+ //
// The palette maps color indexes into actual Color's.
- //
+ //
// Attr's FGCOLOR and BGCOLOR store either 0 to imply "default" or
// the palette index + 1. So use methods Attr.foregroundColor() and
// backgroudnColor() to convert Attr values to the indexes into the palette.
@@ -665,25 +665,25 @@ public class Term extends JComponent implements Accessible {
l.sizeChanged(cells, pixels);
}
}
-
+
private void fireTitleChanged(String title) {
for (TermListener l : listeners) {
l.titleChanged(title);
}
}
-
+
private void fireCwdChanged(String cwd) {
for (TermListener l : listeners) {
l.cwdChanged(cwd);
}
}
-
+
private void fireExternalCommand(String command) {
for (TermListener l : listeners) {
l.externalToolCalled(command);
}
}
-
+
private final java.util.List<TermListener> listeners = new CopyOnWriteArrayList<>();
/**
@@ -807,10 +807,10 @@ public class Term extends JComponent implements Accessible {
}
return line.stringBuffer().toString();
}
-
+
private Keymap keymap;
private Set<String> allowedActions;
-
+
/**
* Set keymap and allowed actions
* @param keymap - use this to check if a keystroke is used outside the terminal
@@ -889,7 +889,7 @@ public class Term extends JComponent implements Accessible {
System.out.println("\tKS = " + ks); // NOI18N
System.out.println("\tcontained = " + keystroke_set.contains(ks)); // NOI18N
}
-
+
if (keystroke_set == null || !keystroke_set.contains(ks)) {
e.consume();
@@ -1089,7 +1089,7 @@ public class Term extends JComponent implements Accessible {
* @param begin
* @param offset
* @param length
- * @return
+ * @return
*/
@SuppressWarnings({"AssignmentToMethodParameter", "ValueOfIncrementOrDecrementUsed"})
public Extent extentInLogicalLine(Coord begin, int offset, int length) {
@@ -1728,9 +1728,9 @@ public class Term extends JComponent implements Accessible {
}
if (f != null) {
- setFont(new Font(Font.MONOSPACED, Font.PLAIN, f.getSize() + 1)); // NOI18N
+ setFont(new Font("Monospaced", Font.PLAIN, f.getSize() + 1)); // NOI18N
} else {
- setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); // NOI18N
+ setFont(new Font("Monospaced", Font.PLAIN, 12)); // NOI18N
}
BorderLayout layout = new BorderLayout();
@@ -2082,7 +2082,7 @@ public class Term extends JComponent implements Accessible {
System.out.println("Selection: '" + sel.sel_get() + "'"); // NOI18N
*/
pasteFromSelection();
-
+
// See IZ 193527
if (click_to_type) {
requestFocus();
@@ -2355,7 +2355,7 @@ public class Term extends JComponent implements Accessible {
try {
String string;
string = (String) contents.getTransferData(DataFlavor.stringFlavor);
-
+
// bug #237034
if (string == null) {
return;
@@ -2635,7 +2635,7 @@ public class Term extends JComponent implements Accessible {
* coordinate system.
* It returns the pixel of the upper left corner of the target cell.
* @param target
- * @return
+ * @return
*/
public Point toPixel(Coord target) {
BCoord btarget = target.toBCoord(firsta);
@@ -2678,7 +2678,7 @@ public class Term extends JComponent implements Accessible {
* <p>
* In the returned Point, x represents the column, y the row.
* @param p
- * @return
+ * @return
*/
public Point mapToViewRowCol(Point p) {
BCoord c = toViewCoord(p);
@@ -2691,7 +2691,7 @@ public class Term extends JComponent implements Accessible {
* <p>
* In the returned Point, x represents the column, y the row.
* @param p
- * @return
+ * @return
*/
public Point mapToBufRowCol(Point p) {
BCoord c = toBufCoords(toViewCoord(p));
@@ -2808,7 +2808,7 @@ public class Term extends JComponent implements Accessible {
for (int gx = 0; gx < n; gx++) {
newp.x = col;
gv.setGlyphPosition(gx, newp);
- col += l.stringWidth(metrics, start + gx);
+ col += l.width(metrics, start + gx) * metrics.width;
}
}
/**
@@ -3271,7 +3271,7 @@ public class Term extends JComponent implements Accessible {
}
g.setXORMode(actual_background);
- int rect_x = cursor_line().stringWidth(metrics, cursor_col) +
+ int rect_x = cursor_col * metrics.width +
glyph_gutter_width +
debug_gutter_width;
int rect_y = cursor_row * metrics.height;
@@ -3564,7 +3564,7 @@ public class Term extends JComponent implements Accessible {
}
cht();
}
-
+
private boolean cht() {
// SHOULD do something better with tabs near the end of the line
// On the other hand, that's how ANSI terminals are supposed
@@ -4189,7 +4189,7 @@ public class Term extends JComponent implements Accessible {
System.out.println("op_cwd(" + currentWorkingDirectory + ")"); // NOI18N
}
}
-
+
@Override
public void op_ext(String command) {
fireExternalCommand(command);
@@ -5073,7 +5073,7 @@ public class Term extends JComponent implements Accessible {
/**
* Returns the actual drawing area so events can be interposed upon,
* like context menus.
- * @return
+ * @return
* @deprecated Replaced by{@link #getScreen()}.
*/
@Deprecated
@@ -5084,7 +5084,7 @@ public class Term extends JComponent implements Accessible {
/**
* Returns the actual drawing area so events can be interposed upon,
* like context menus.
- * @return
+ * @return
*/
public JComponent getScreen() {
return screen;
@@ -5093,7 +5093,7 @@ public class Term extends JComponent implements Accessible {
/**
* Return the terminal operations implementation.
* <b>WARNING! This is temporary</b>
- * @return
+ * @return
*/
public Ops ops() {
return ops;
@@ -5472,7 +5472,7 @@ public class Term extends JComponent implements Accessible {
return tab_size;
}
private int tab_size = 8;
-
+
/**
* Set select-by-word delimiters.
* <p>
@@ -5636,7 +5636,7 @@ public class Term extends JComponent implements Accessible {
public final void setRenderingHints(Map<?, ?> hints) {
renderingHints = hints;
}
-
+
/**
* Clear everything and assign new text.
* <p>
@@ -5800,7 +5800,7 @@ public class Term extends JComponent implements Accessible {
/**
* Return the cell width of the given character.
* @param c
- * @return
+ * @return
*/
public int charWidth(char c) {
return metrics.wcwidth(c);
@@ -5840,11 +5840,11 @@ public class Term extends JComponent implements Accessible {
if (isFixedFont()) {
font = new_font;
} else {
- font = new Font(Font.MONOSPACED, // NOI18N
+ font = new Font("Monospaced", // NOI18N
new_font.getStyle(),
new_font.getSize());
}
-
+
super.setFont(font); // This should invalidate us, which
// ultimately will cause a repaint
@@ -5856,7 +5856,7 @@ public class Term extends JComponent implements Accessible {
*/
// cache the metrics
- metrics = new MyFontMetrics(this);
+ metrics = new MyFontMetrics(this, font);
updateScreenSize();
}
@@ -5999,7 +5999,7 @@ public class Term extends JComponent implements Accessible {
* This function really should be private but I need it to be public for
* unit-testing purposes.
* @param c
- * @return
+ * @return
*/
public int CoordToPosition(Coord c) {
BCoord b = c.toBCoord(firsta);
@@ -6023,7 +6023,7 @@ public class Term extends JComponent implements Accessible {
* This function really should be private but I need it to be public for
* unit-testing purposes.
* @param position
- * @return
+ * @return
*/
public Coord PositionToCoord(int position) {
int nchars = charsInPrehistory;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists