mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
fix search+replace on empty files
This commit is contained in:
parent
995f39b61f
commit
6ecf7be826
2 changed files with 29 additions and 12 deletions
|
|
@ -1172,7 +1172,14 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
}
|
}
|
||||||
else if (opts.from === 'ClickApply') {
|
else if (opts.from === 'ClickApply') {
|
||||||
if (this._settingsService.state.globalSettings.enableFastApply) {
|
if (this._settingsService.state.globalSettings.enableFastApply) {
|
||||||
res = await this._initializeSearchAndReplaceStream(opts) // fast apply
|
const numCharsInFile = this._fileLengthOfGivenURI(opts.uri)
|
||||||
|
if (numCharsInFile === null) return null
|
||||||
|
if (numCharsInFile < 1000) { // slow apply for short files (especially important for empty files)
|
||||||
|
res = await this._initializeWriteoverStream(opts)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res = await this._initializeSearchAndReplaceStream(opts) // fast apply
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res = await this._initializeWriteoverStream(opts) // rewrite
|
res = await this._initializeWriteoverStream(opts) // rewrite
|
||||||
|
|
@ -1311,7 +1318,7 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
let ctrlKZoneIfQuickEdit: CtrlKZone | null = null
|
let ctrlKZoneIfQuickEdit: CtrlKZone | null = null
|
||||||
|
|
||||||
if (from === 'ClickApply') {
|
if (from === 'ClickApply') {
|
||||||
const uri_ = this._getActiveEditorURI()
|
const uri_ = this._uriOfGivenURI(opts.uri)
|
||||||
if (!uri_) return
|
if (!uri_) return
|
||||||
uri = uri_
|
uri = uri_
|
||||||
startRange = 'fullFile'
|
startRange = 'fullFile'
|
||||||
|
|
@ -1505,19 +1512,29 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_uriOfGivenURI(givenURI: URI | 'current') {
|
||||||
private async _initializeSearchAndReplaceStream(opts: StartApplyingOpts & { from: 'ClickApply' }): Promise<[DiffZone, Promise<void>] | undefined> {
|
|
||||||
const { from, applyStr, uri: givenURI, } = opts
|
|
||||||
let uri: URI
|
|
||||||
|
|
||||||
if (givenURI === 'current') {
|
if (givenURI === 'current') {
|
||||||
const uri_ = this._getActiveEditorURI()
|
const uri_ = this._getActiveEditorURI()
|
||||||
if (!uri_) return
|
if (!uri_) return
|
||||||
uri = uri_
|
return uri_
|
||||||
}
|
|
||||||
else {
|
|
||||||
uri = givenURI
|
|
||||||
}
|
}
|
||||||
|
return givenURI
|
||||||
|
}
|
||||||
|
_fileLengthOfGivenURI(givenURI: URI | 'current') {
|
||||||
|
const uri = this._uriOfGivenURI(givenURI)
|
||||||
|
if (!uri) return null
|
||||||
|
const { model } = this._voidModelService.getModel(uri)
|
||||||
|
if (!model) return null
|
||||||
|
const numCharsInFile = model.getValueLength(EndOfLinePreference.LF)
|
||||||
|
return numCharsInFile
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async _initializeSearchAndReplaceStream(opts: StartApplyingOpts & { from: 'ClickApply' }): Promise<[DiffZone, Promise<void>] | undefined> {
|
||||||
|
const { from, applyStr, uri: givenURI, } = opts
|
||||||
|
|
||||||
|
const uri = this._uriOfGivenURI(givenURI)
|
||||||
|
if (!uri) return
|
||||||
|
|
||||||
await this._voidModelService.initializeModel(uri)
|
await this._voidModelService.initializeModel(uri)
|
||||||
const { model } = this._voidModelService.getModel(uri)
|
const { model } = this._voidModelService.getModel(uri)
|
||||||
|
|
|
||||||
|
|
@ -271,8 +271,8 @@ const VoidCommandBar = ({ uri, editor }: VoidCommandBarProps) => {
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
{/* Changes in file */}
|
{/* Changes in file */}
|
||||||
<div className={`${!isADiffZoneInThisFile ? 'hidden' : ''} flex items-center ${upDownDisabled ? 'opacity-50' : ''}`}>
|
<div className={`${!isADiffZoneInThisFile ? 'hidden' : ''} flex items-center ${upDownDisabled ? 'opacity-50' : ''}`}>
|
||||||
{downButton}
|
|
||||||
{upButton}
|
{upButton}
|
||||||
|
{downButton}
|
||||||
<span className="min-w-16 px-2 text-xs">
|
<span className="min-w-16 px-2 text-xs">
|
||||||
{isADiffInThisFile ?
|
{isADiffInThisFile ?
|
||||||
`Diff ${(currDiffIdx ?? 0) + 1} of ${sortedDiffIds.length}`
|
`Diff ${(currDiffIdx ?? 0) + 1} of ${sortedDiffIds.length}`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue