feat(editor): add CSV-to-markdown-table toolbar converter

Amit Haridas
This commit is contained in:
2026-08-23 19:31:33 +05:30
parent 63c35ef2dc
commit 1f5db511ba
4 changed files with 184 additions and 1 deletions
+26
View File
@@ -12,6 +12,7 @@ const hljs = require('highlight.js');
const { createEditor } = require('./editor/codemirror-setup');
const { undo, redo } = require('@codemirror/commands');
const { showMediaOperationsDialog } = require('./renderer/media-operations-dialog');
const { csvToMarkdownTable } = require('./utils/csv-to-markdown-table');
/**
* Toggle body classes that drive the monospace font + ligatures CSS tokens.
@@ -1212,6 +1213,11 @@ class TabManager {
this.insertTable();
});
// CSV to Table (converts the selected CSV text in place)
document.getElementById('btn-csv-table').addEventListener('click', () => {
this.convertSelectionToTable();
});
// Strikethrough
document.getElementById('btn-strikethrough').addEventListener('click', () => {
this.wrapSelection('~~', '~~');
@@ -1284,6 +1290,26 @@ class TabManager {
this.insertAtCursor(table);
}
// Convert the selected CSV text into a markdown table in place
convertSelectionToTable() {
const tab = this.tabs.get(this.activeTabId);
if (!tab?.editorView) return;
const view = tab.editorView;
const { from, to } = view.state.selection.main;
const selectedText = view.state.sliceDoc(from, to);
if (!selectedText.trim()) return;
const table = csvToMarkdownTable(selectedText);
if (!table) return;
view.dispatch({
changes: {
from,
to,
insert: table,
},
});
view.focus();
}
// Insert a code block
insertCodeBlock() {
const tab = this.tabs.get(this.activeTabId);