#211 - Replace text selection on media insert

This commit is contained in:
Elio Struyf
2021-12-26 12:11:38 +01:00
parent 24f79d9d3f
commit 092eb0fd2a
2 changed files with 11 additions and 2 deletions
+2 -1
View File
@@ -4,11 +4,12 @@
### 🎨 Enhancements
- [#211](https://github.com/estruyf/vscode-front-matter/issues/211): Replace text selection on media inserts
### 🐞 Fixes
- [#210](https://github.com/estruyf/vscode-front-matter/issues/210): Fix for adding media files with uppercase file extensions
## [5.8.0] - 2021-12-21 - 🎄
### 🎨 Enhancements
+9 -1
View File
@@ -283,7 +283,15 @@ export class MediaHelpers {
}
}
await editor?.edit(builder => builder.insert(new Position(line, character), data.snippet || `![${data.alt || data.caption || ""}](${imgPath})`));
const selection = editor?.selection;
await editor?.edit(builder => {
const snippet = data.snippet || `![${data.alt || data.caption || ""}](${imgPath})`;
if (selection !== undefined) {
builder.replace(selection, snippet);
} else {
builder.insert(new Position(line, character), snippet);
}
});
}
panel.getMediaSelection();
} else {