Fix calculation of row number for selection and URL clicking

When calculating the row that is clicked, for mouse tracking
mFontLineSpacingAndAscent was taken into account, but for selection and
URL clicking it wasn't. This adds a common function for calculating the
column and row which does take it into account and use that for all
three.

I'm not quite sure why it's necessary to subtract
mFontLineSpacingAndAscent, but with this calculation the click location
matches the line that is acted on for me with both touch and mouse and
on different font sizes.

It also removes the offset for finger the selection/url used because I
don't think it's common for apps on Android to have such an offset, and
because the mouse tracking did not use such an offset.
This commit is contained in:
Trygve Aaberge
2021-09-14 21:06:16 +02:00
parent 1a5a66d0ee
commit 54bb83de41
3 changed files with 29 additions and 17 deletions

View File

@@ -88,19 +88,10 @@ public class TextSelectionCursorController implements CursorController {
}
}
public int[] getXAndYFromEvent(MotionEvent event) {
int cx = (int) (event.getX() / terminalView.mRenderer.getFontWidth());
final boolean eventFromMouse = event.isFromSource(InputDevice.SOURCE_MOUSE);
// Offset for finger:
final int SELECT_TEXT_OFFSET_Y = eventFromMouse ? 0 : -40;
int cy = (int) ((event.getY() + SELECT_TEXT_OFFSET_Y) / terminalView.mRenderer.getFontLineSpacing()) + terminalView.getTopRow();
return new int[] { cx, cy };
}
public void setInitialTextSelectionPosition(MotionEvent event) {
int[] xAndY = getXAndYFromEvent(event);
mSelX1 = mSelX2 = xAndY[0];
mSelY1 = mSelY2 = xAndY[1];
int[] columnAndRow = terminalView.getColumnAndRow(event, true);
mSelX1 = mSelX2 = columnAndRow[0];
mSelY1 = mSelY2 = columnAndRow[1];
TerminalBuffer screen = terminalView.mEmulator.getScreen();
if (!" ".equals(screen.getSelectedText(mSelX1, mSelY1, mSelX1, mSelY1))) {