From 0045c1f31b23bb70426f38cb5ce8afc28abb67b5 Mon Sep 17 00:00:00 2001 From: Matteo Luppi <100372313+lups2000@users.noreply.github.com> Date: Tue, 10 Dec 2024 21:19:06 +0100 Subject: [PATCH] allow single click to edit URL request (#7385) * allow single click to edit URL request * update changelog * [autofix.ci] apply automated fixes * update changelog * use 'selectAllOnClick' instead of 'setCursorOnClick' * remove 'selectAllOnClick' from capture tab page --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- CHANGELOG.md | 2 ++ web/src/js/components/FlowView/Comment.tsx | 1 + .../js/components/FlowView/HttpMessages.tsx | 5 ++++ web/src/js/components/Modes/Reverse.tsx | 4 ++-- .../components/editors/KeyValueListEditor.tsx | 2 ++ web/src/js/components/editors/ValueEditor.tsx | 23 +++++++++++++------ 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a7a02ba7..397a3ea03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ - Add cache-busting for mitmweb's front end code. ([#7386](https://github.com/mitmproxy/mitmproxy/pull/7386), @mhils) +- Clicking the URL in mitmweb now places the cursor at the current position instead of selecting the entire URL. + ([#7385](https://github.com/mitmproxy/mitmproxy/pull/7385), @lups2000) ## 05 December 2024: mitmproxy 11.0.2 diff --git a/web/src/js/components/FlowView/Comment.tsx b/web/src/js/components/FlowView/Comment.tsx index 0f3c7c66e..bfb3d786c 100644 --- a/web/src/js/components/FlowView/Comment.tsx +++ b/web/src/js/components/FlowView/Comment.tsx @@ -17,6 +17,7 @@ export default function Comment({ flow }: { flow: Flow }) { dispatch(flowActions.update(flow, { comment })); }} placeholder="empty" + selectAllOnClick={true} /> ); diff --git a/web/src/js/components/FlowView/HttpMessages.tsx b/web/src/js/components/FlowView/HttpMessages.tsx index 82012e9ed..b5703c48f 100644 --- a/web/src/js/components/FlowView/HttpMessages.tsx +++ b/web/src/js/components/FlowView/HttpMessages.tsx @@ -33,6 +33,7 @@ function RequestLine({ flow }: RequestLineProps) { ) } isValid={(method) => method.length > 0} + selectAllOnClick={true} />   @@ -82,6 +84,7 @@ function ResponseLine({ flow }: ResponseLineProps) { ) } isValid={isValidHttpVersion} + selectAllOnClick={true} />   /^\d+$/.test(code)} + selectAllOnClick={true} /> {flow.response.http_version !== "HTTP/2.0" && ( <> @@ -105,6 +109,7 @@ function ResponseLine({ flow }: ResponseLineProps) { flowActions.update(flow, { response: { msg } }), ) } + selectAllOnClick={true} /> )} diff --git a/web/src/js/components/Modes/Reverse.tsx b/web/src/js/components/Modes/Reverse.tsx index 1aea1bc29..20516f14a 100644 --- a/web/src/js/components/Modes/Reverse.tsx +++ b/web/src/js/components/Modes/Reverse.tsx @@ -115,7 +115,7 @@ function ReverseToggleRow({

Advanced Configuration

Listen Host

dispatch(setListenHost({ server, value })) @@ -124,7 +124,7 @@ function ReverseToggleRow({ />

Listen Port

dispatch( diff --git a/web/src/js/components/editors/KeyValueListEditor.tsx b/web/src/js/components/editors/KeyValueListEditor.tsx index 16b7e82f4..ee0b75cf6 100644 --- a/web/src/js/components/editors/KeyValueListEditor.tsx +++ b/web/src/js/components/editors/KeyValueListEditor.tsx @@ -36,6 +36,7 @@ class Row extends Component { onEditDone={(newKey) => this.props.onEditDone([newKey, value]) } + selectAllOnClick={true} /> :  { this.props.onEditDone([key, newVal]) } placeholder="empty" + selectAllOnClick={true} /> ); diff --git a/web/src/js/components/editors/ValueEditor.tsx b/web/src/js/components/editors/ValueEditor.tsx index 6f5d84f2d..c307c1a91 100644 --- a/web/src/js/components/editors/ValueEditor.tsx +++ b/web/src/js/components/editors/ValueEditor.tsx @@ -9,6 +9,7 @@ export interface ValueEditorProps { onInput?: (newVal: string) => void; onKeyDown?: (e: React.KeyboardEvent) => void; placeholder?: string; + selectAllOnClick?: boolean; } /** "plaintext-only" for browsers which support it, "true" for everyone else */ @@ -69,11 +70,13 @@ export default class ValueEditor extends Component { this.input.current.focus(); this.suppress_events = false; - const range = document.createRange(); - range.selectNodeContents(this.input.current); - const sel = window.getSelection(); - sel?.removeAllRanges(); - sel?.addRange(range); + if (this.props.selectAllOnClick) { + const range = document.createRange(); + range.selectNodeContents(this.input.current); + const sel = window.getSelection(); + sel?.removeAllRanges(); + sel?.addRange(range); + } this.props.onEditStart?.(); }); @@ -125,8 +128,14 @@ export default class ValueEditor extends Component { has_not_selected_text, ); - if (still_on_elem && has_not_selected_text) { - this.startEditing(); + if (this.props.selectAllOnClick) { + if (still_on_elem && has_not_selected_text) { + this.startEditing(); + } + } else { + if (still_on_elem) { + this.startEditing(); + } } this.suppress_events = false; };