mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
Support clicking directly on a URL to open it
This allows you to click/press directly on a URL in the terminal view to open it. It takes priority over opening the keyboard, so if you click on a URL it is opened, and if you click anywhere else the keyboard opens like before. Currently, if the application in the terminal is tracking the mouse and you click on a URL, both actions happen. The mouse event is sent to the application, and the URL is also opened. To enable support for this, you have to set `terminal-onclick-url-open=true` in `termux.properties`.
This commit is contained in:
@@ -94,7 +94,7 @@ public final class TerminalView extends View {
|
||||
@Override
|
||||
public boolean onUp(MotionEvent event) {
|
||||
mScrollRemainder = 0.0f;
|
||||
if (mEmulator != null && mEmulator.isMouseTrackingActive() && !isSelectingText() && !scrolledWithFinger) {
|
||||
if (mEmulator != null && mEmulator.isMouseTrackingActive() && !event.isFromSource(InputDevice.SOURCE_MOUSE) && !isSelectingText() && !scrolledWithFinger) {
|
||||
// Quick event processing when mouse tracking is active - do not wait for check of double tapping
|
||||
// for zooming.
|
||||
sendMouseEventCode(event, TerminalEmulator.MOUSE_LEFT_BUTTON, true);
|
||||
@@ -114,13 +114,8 @@ public final class TerminalView extends View {
|
||||
return true;
|
||||
}
|
||||
requestFocus();
|
||||
if (!mEmulator.isMouseTrackingActive()) {
|
||||
if (!event.isFromSource(InputDevice.SOURCE_MOUSE)) {
|
||||
mClient.onSingleTapUp(event);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
mClient.onSingleTapUp(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -550,7 +545,6 @@ public final class TerminalView extends View {
|
||||
sendMouseEventCode(event, TerminalEmulator.MOUSE_LEFT_BUTTON_MOVED, true);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1135,7 +1129,7 @@ public final class TerminalView extends View {
|
||||
/**
|
||||
* Define functions required for text selection and its handles.
|
||||
*/
|
||||
TextSelectionCursorController getTextSelectionCursorController() {
|
||||
public TextSelectionCursorController getTextSelectionCursorController() {
|
||||
if (mTextSelectionCursorController == null) {
|
||||
mTextSelectionCursorController = new TextSelectionCursorController(this);
|
||||
|
||||
|
@@ -88,15 +88,19 @@ public class TextSelectionCursorController implements CursorController {
|
||||
}
|
||||
}
|
||||
|
||||
public void setInitialTextSelectionPosition(MotionEvent event) {
|
||||
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 };
|
||||
}
|
||||
|
||||
mSelX1 = mSelX2 = cx;
|
||||
mSelY1 = mSelY2 = cy;
|
||||
public void setInitialTextSelectionPosition(MotionEvent event) {
|
||||
int[] xAndY = getXAndYFromEvent(event);
|
||||
mSelX1 = mSelX2 = xAndY[0];
|
||||
mSelY1 = mSelY2 = xAndY[1];
|
||||
|
||||
TerminalBuffer screen = terminalView.mEmulator.getScreen();
|
||||
if (!" ".equals(screen.getSelectedText(mSelX1, mSelY1, mSelX1, mSelY1))) {
|
||||
|
Reference in New Issue
Block a user