mirror of
https://github.com/voideditor/void
synced 2026-05-23 17:38: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') {
|
||||
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 {
|
||||
res = await this._initializeWriteoverStream(opts) // rewrite
|
||||
|
|
@ -1311,7 +1318,7 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
|||
let ctrlKZoneIfQuickEdit: CtrlKZone | null = null
|
||||
|
||||
if (from === 'ClickApply') {
|
||||
const uri_ = this._getActiveEditorURI()
|
||||
const uri_ = this._uriOfGivenURI(opts.uri)
|
||||
if (!uri_) return
|
||||
uri = uri_
|
||||
startRange = 'fullFile'
|
||||
|
|
@ -1505,19 +1512,29 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
|||
|
||||
|
||||
|
||||
|
||||
private async _initializeSearchAndReplaceStream(opts: StartApplyingOpts & { from: 'ClickApply' }): Promise<[DiffZone, Promise<void>] | undefined> {
|
||||
const { from, applyStr, uri: givenURI, } = opts
|
||||
let uri: URI
|
||||
|
||||
_uriOfGivenURI(givenURI: URI | 'current') {
|
||||
if (givenURI === 'current') {
|
||||
const uri_ = this._getActiveEditorURI()
|
||||
if (!uri_) return
|
||||
uri = uri_
|
||||
}
|
||||
else {
|
||||
uri = givenURI
|
||||
return uri_
|
||||
}
|
||||
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)
|
||||
const { model } = this._voidModelService.getModel(uri)
|
||||
|
|
|
|||
|
|
@ -271,8 +271,8 @@ const VoidCommandBar = ({ uri, editor }: VoidCommandBarProps) => {
|
|||
<div className="flex flex-col gap-1">
|
||||
{/* Changes in file */}
|
||||
<div className={`${!isADiffZoneInThisFile ? 'hidden' : ''} flex items-center ${upDownDisabled ? 'opacity-50' : ''}`}>
|
||||
{downButton}
|
||||
{upButton}
|
||||
{downButton}
|
||||
<span className="min-w-16 px-2 text-xs">
|
||||
{isADiffInThisFile ?
|
||||
`Diff ${(currDiffIdx ?? 0) + 1} of ${sortedDiffIds.length}`
|
||||
|
|
|
|||
Loading…
Reference in a new issue