mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
ctrlK roundRange
This commit is contained in:
parent
2ba04a78a8
commit
dd133d2cd5
6 changed files with 19 additions and 15 deletions
|
|
@ -11,6 +11,7 @@ import { IMetricsService } from '../../../../platform/void/common/metricsService
|
|||
import { ICodeEditorService } from '../../../../editor/browser/services/codeEditorService.js';
|
||||
import { IInlineDiffsService } from './inlineDiffsService.js';
|
||||
import { InputBox } from '../../../../base/browser/ui/inputbox/inputBox.js';
|
||||
import { roundRangeToLines } from './sidebarActions.js';
|
||||
|
||||
|
||||
export type QuickEditPropsType = {
|
||||
|
|
@ -54,7 +55,7 @@ registerAction2(class extends Action2 {
|
|||
if (!editor) return;
|
||||
const model = editor.getModel()
|
||||
if (!model) return;
|
||||
const selection = editor.getSelection()
|
||||
const selection = roundRangeToLines(editor.getSelection(), { emptySelectionBehavior: 'line' })
|
||||
if (!selection) return;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -146,9 +146,9 @@ export const QuickEditChat = ({ diffareaid, onGetInputBox, onUserUpdateText, onC
|
|||
</div>
|
||||
|
||||
<div className='absolute pt-1 -top-1 -right-1'>
|
||||
<span className='cursor-pointer hover:bg-red-500 rounded-md z-1'>
|
||||
<span className='cursor-pointer rounded-md z-1'>
|
||||
<X
|
||||
className='size-3 text-vscode-toolbar-foreground'
|
||||
className='size-4 text-vscode-toolbar-foreground'
|
||||
onClick={onX}
|
||||
/>
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ export const Sidebar = ({ className }: { className: string }) => {
|
|||
sidebarStateService.setState({ currentTab: tabs[(index + 1) % tabs.length] as any })
|
||||
}}>clickme {tab}</span> */}
|
||||
|
||||
<div className={`w-full h-auto mb-2 ${isHistoryOpen ? '' : 'hidden'} ring-2 ring-widget-shadow z-10`}>
|
||||
<div className={`w-full h-auto mb-2 ${isHistoryOpen ? '' : 'hidden'} ring-inset ring-2 ring-widget-shadow z-10`}>
|
||||
<ErrorBoundary>
|
||||
<SidebarThreadSelector />
|
||||
</ErrorBoundary>
|
||||
|
|
|
|||
|
|
@ -197,11 +197,12 @@ export const VoidCheckBox = ({ label, value, onClick, className }: { label: stri
|
|||
}
|
||||
|
||||
|
||||
export const VoidSelectBox = <T,>({ onChangeSelection, onCreateInstance, selectBoxRef, options }: {
|
||||
export const VoidSelectBox = <T,>({ onChangeSelection, onCreateInstance, selectBoxRef, options, className }: {
|
||||
onChangeSelection: (value: T) => void;
|
||||
onCreateInstance?: ((instance: SelectBox) => void | IDisposable[]);
|
||||
selectBoxRef?: React.MutableRefObject<SelectBox | null>;
|
||||
options: readonly { text: string, value: T }[];
|
||||
className?:string;
|
||||
}) => {
|
||||
const accessor = useAccessor()
|
||||
const contextViewProvider = accessor.get('IContextViewService')
|
||||
|
|
@ -209,10 +210,9 @@ export const VoidSelectBox = <T,>({ onChangeSelection, onCreateInstance, selectB
|
|||
let containerRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
return <WidgetComponent
|
||||
className='@@select-child-restyle
|
||||
className={`@@select-child-restyle
|
||||
@@[&_select]:!void-text-void-fg-3
|
||||
@@[&_select]:!void-text-xs
|
||||
'
|
||||
${className ?? ''}`}
|
||||
ctor={SelectBox}
|
||||
propsFn={useCallback((container) => {
|
||||
containerRef.current = container
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ const ModelSelectBox = ({ options, featureName }: { options: ModelOption[], feat
|
|||
let weChangedText = false
|
||||
|
||||
return <VoidSelectBox
|
||||
className='@@[&_select]:!void-text-xs'
|
||||
options={options}
|
||||
onChangeSelection={useCallback((newVal: ModelSelection) => {
|
||||
if (weChangedText) return
|
||||
|
|
|
|||
|
|
@ -26,13 +26,17 @@ import { VOID_OPEN_SETTINGS_ACTION_ID } from './voidSettingsPane.js';
|
|||
// ---------- Register commands and keybindings ----------
|
||||
|
||||
|
||||
const roundRangeToLines = (range: IRange | null | undefined) => {
|
||||
export const roundRangeToLines = (range: IRange | null | undefined, options: { emptySelectionBehavior: 'null' | 'line' }) => {
|
||||
if (!range)
|
||||
return null
|
||||
|
||||
// treat as no selection if selection is empty
|
||||
if (range.endColumn === range.startColumn && range.endLineNumber === range.startLineNumber)
|
||||
return null
|
||||
if (range.endColumn === range.startColumn && range.endLineNumber === range.startLineNumber) {
|
||||
if (options.emptySelectionBehavior === 'null')
|
||||
return null
|
||||
else if (options.emptySelectionBehavior === 'line')
|
||||
return { startLineNumber: range.startLineNumber, startColumn: 1, endLineNumber: range.startLineNumber, endColumn: 1 }
|
||||
}
|
||||
|
||||
// IRange is 1-indexed
|
||||
const endLine = range.endColumn === 1 ? range.endLineNumber - 1 : range.endLineNumber // e.g. if the user triple clicks, it selects column=0, line=line -> column=0, line=line+1
|
||||
|
|
@ -77,10 +81,8 @@ registerAction2(class extends Action2 {
|
|||
stateService.fireFocusChat()
|
||||
|
||||
const editor = editorService.getActiveCodeEditor()
|
||||
const selectionRange = roundRangeToLines(
|
||||
// accessor.get(IEditorService).activeTextEditorControl?.getSelection()
|
||||
editor?.getSelection()
|
||||
)
|
||||
// accessor.get(IEditorService).activeTextEditorControl?.getSelection()
|
||||
const selectionRange = roundRangeToLines(editor?.getSelection(), { emptySelectionBehavior: 'null' })
|
||||
|
||||
|
||||
// select whole lines
|
||||
|
|
|
|||
Loading…
Reference in a new issue