Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notebook find/replace corrupts notebook #194932

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/search/browser/replaceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class ReplaceService implements IReplaceService {

if (arg instanceof Match) {
if (arg instanceof MatchInNotebook) {
if (!arg.isWebviewMatch()) {
if (!arg.isReadonly()) {
// only apply edits if it's not a webview match, since webview matches are read-only
const match = <MatchInNotebook>arg;
edits.push(this.createEdit(match, match.replaceString, match.cell.uri));
Expand Down
16 changes: 12 additions & 4 deletions src/vs/workbench/contrib/search/browser/searchModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ export class CellMatch {
this._context = new Map<number, string>();
}

public hasCellViewModel() {
return !(this._cell instanceof CellSearchModel);
}

get context(): Map<number, string> {
return new Map(this._context);
}
Expand Down Expand Up @@ -304,6 +308,10 @@ export class MatchInNotebook extends Match {
return this._webviewIndex !== undefined;
}

public isReadonly() {
return (!this._cellParent.hasCellViewModel()) || this.isWebviewMatch();
}

get cellIndex() {
return this._cellParent.cellIndex;
}
Expand Down Expand Up @@ -448,8 +456,8 @@ export class FileMatch extends Disposable implements IFileMatch {
return this._closestRoot;
}

hasWebviewMatches(): boolean {
return this.matches().some(m => m instanceof MatchInNotebook && m.isWebviewMatch());
hasReadonlyMatches(): boolean {
return this.matches().some(m => m instanceof MatchInNotebook && m.isReadonly());
}

createMatches(): void {
Expand Down Expand Up @@ -727,7 +735,7 @@ export class FileMatch extends Disposable implements IFileMatch {
}

hasOnlyReadOnlyMatches(): boolean {
return this.matches().every(match => (match instanceof MatchInNotebook && match.isWebviewMatch()));
return this.matches().every(match => (match instanceof MatchInNotebook && match.isReadonly()));
}

// #region strictly notebook methods
Expand Down Expand Up @@ -1269,7 +1277,7 @@ export class FolderMatch extends Disposable {
const removed = [];
for (const match of fileMatches as FileMatch[]) {
if (this._fileMatches.get(match.resource)) {
if (keepReadonly && match.hasWebviewMatches()) {
if (keepReadonly && match.hasReadonlyMatches()) {
continue;
}
this._fileMatches.delete(match.resource);
Expand Down
6 changes: 4 additions & 2 deletions src/vs/workbench/contrib/search/browser/searchResultsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ export class MatchRenderer extends Disposable implements ICompressibleTreeRender
renderElement(node: ITreeNode<Match, any>, index: number, templateData: IMatchTemplate): void {
const match = node.element;
const preview = match.preview();
const replace = this.searchModel.isReplaceActive() && !!this.searchModel.replaceString && !(match instanceof MatchInNotebook && match.isWebviewMatch());
const replace = this.searchModel.isReplaceActive() &&
!!this.searchModel.replaceString &&
!(match instanceof MatchInNotebook && match.isReadonly());

templateData.before.textContent = preview.before;
templateData.match.textContent = preview.inside;
Expand All @@ -361,7 +363,7 @@ export class MatchRenderer extends Disposable implements ICompressibleTreeRender
templateData.after.textContent = preview.after;
templateData.parent.title = (preview.before + (replace ? match.replaceString : preview.inside) + preview.after).trim().substr(0, 999);

IsEditableItemKey.bindTo(templateData.contextKeyService).set(!(match instanceof MatchInNotebook && match.isWebviewMatch()));
IsEditableItemKey.bindTo(templateData.contextKeyService).set(!(match instanceof MatchInNotebook && match.isReadonly()));

const numLines = match.range().endLineNumber - match.range().startLineNumber;
const extraLinesStr = numLines > 0 ? `+${numLines}` : '';
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ export class SearchView extends ViewPane {

let editable = false;
if (focus instanceof Match) {
editable = (focus instanceof MatchInNotebook) ? !focus.isWebviewMatch() : true;
editable = (focus instanceof MatchInNotebook) ? !focus.isReadonly() : true;
} else if (focus instanceof FileMatch) {
editable = !focus.hasOnlyReadOnlyMatches();
} else if (focus instanceof FolderMatch) {
Expand Down