Skip to content

Commit 0afe08d

Browse files
committed
feat: add diff strategy selection in chat text area
1 parent 0a32e24 commit 0afe08d

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

webview-ui/src/components/chat/ChatTextArea.tsx

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,30 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
5050
},
5151
ref,
5252
) => {
53-
const { filePaths, currentApiConfigName, listApiConfigMeta, customModes } = useExtensionState()
53+
const {
54+
filePaths,
55+
currentApiConfigName,
56+
listApiConfigMeta,
57+
customModes,
58+
diffEnabled,
59+
setDiffEnabled,
60+
experimentalDiffStrategy,
61+
setExperimentalDiffStrategy,
62+
} = useExtensionState()
5463
const [gitCommits, setGitCommits] = useState<any[]>([])
5564
const [showDropdown, setShowDropdown] = useState(false)
65+
const [diffStrategy, setDiffStrategy] = useState<string>("search-replace") // Default to 'search-replace'
66+
67+
// Initialize diffStrategy based on extension state
68+
useEffect(() => {
69+
if (!diffEnabled) {
70+
setDiffStrategy("whole")
71+
} else if (experimentalDiffStrategy) {
72+
setDiffStrategy("unified-diff")
73+
} else {
74+
setDiffStrategy("search-replace")
75+
}
76+
}, [diffEnabled, experimentalDiffStrategy])
5677

5778
// Close dropdown when clicking outside
5879
useEffect(() => {
@@ -470,7 +491,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
470491

471492
highlightLayerRef.current.innerHTML = text
472493
.replace(/\n$/, "\n\n")
473-
.replace(/[<>&]/g, (c) => ({ "<": "&lt;", ">": "&gt;", "&": "&amp;" })[c] || c)
494+
.replace(/[<>&]/g, (c) => ({ "<": "<", ">": ">", "&": "&amp;" })[c] || c)
474495
.replace(mentionRegexGlobal, '<mark class="mention-context-textarea-highlight">$&</mark>')
475496

476497
highlightLayerRef.current.scrollTop = textAreaRef.current.scrollTop
@@ -799,6 +820,46 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
799820
<CaretIcon />
800821
</div>
801822
</div>
823+
824+
<div
825+
style={{
826+
position: "relative",
827+
display: "inline-block",
828+
flex: "0 1 auto",
829+
minWidth: 0,
830+
maxWidth: "150px",
831+
overflow: "hidden",
832+
}}>
833+
<select
834+
value={diffStrategy}
835+
disabled={textAreaDisabled}
836+
onChange={(e) => {
837+
const value = e.target.value
838+
setDiffStrategy(value)
839+
if (value === "whole") {
840+
setDiffEnabled(false)
841+
setExperimentalDiffStrategy(false)
842+
} else if (value === "search-replace") {
843+
setDiffEnabled(true)
844+
setExperimentalDiffStrategy(false)
845+
} else if (value === "unified-diff") {
846+
setDiffEnabled(true)
847+
setExperimentalDiffStrategy(true)
848+
}
849+
}}
850+
style={{
851+
...selectStyle,
852+
width: "100%",
853+
textOverflow: "ellipsis",
854+
}}>
855+
<option value="whole">whole</option>
856+
<option value="search-replace">search-replace</option>
857+
<option value="unified-diff">unified</option>
858+
</select>
859+
<div style={caretContainerStyle}>
860+
<CaretIcon />
861+
</div>
862+
</div>
802863
</div>
803864

804865
<div

0 commit comments

Comments
 (0)