mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-03 02:11:07 +05:30
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b23e60a704 | ||
|
|
c559b34f3e | ||
|
|
a780f2984a | ||
|
|
0c9961d412 |
@@ -54,8 +54,8 @@ Download the latest release for your platform from the [Releases](https://github
|
|||||||
|
|
||||||
#### Linux
|
#### Linux
|
||||||
- **AppImage**: `PanConverter-1.5.0.AppImage` (universal, may require `--no-sandbox` flag)
|
- **AppImage**: `PanConverter-1.5.0.AppImage` (universal, may require `--no-sandbox` flag)
|
||||||
- **Debian Package**: `pan-converter_1.5.0_amd64.deb`
|
- **Debian Package**: `pan-converter_1.5.6_amd64.deb`
|
||||||
- **Snap Package**: `pan-converter_1.5.0_amd64.snap`
|
- **Snap Package**: `pan-converter_1.5.6_amd64.snap`
|
||||||
|
|
||||||
### Install from Source
|
### Install from Source
|
||||||
```bash
|
```bash
|
||||||
@@ -138,6 +138,8 @@ npm run dist:all
|
|||||||
|
|
||||||
## Version History
|
## Version History
|
||||||
|
|
||||||
|
- **v1.5.6** - (Your release notes here)
|
||||||
|
- **v1.5.5** - Refactored PDF export, simplified Pandoc pathing, and removed XLSX dependency.
|
||||||
- **v1.3.1** - Bug fixes: Fixed file associations for double-clicking .md files, corrected 50/50 layout alignment for editor/preview panes
|
- **v1.3.1** - Bug fixes: Fixed file associations for double-clicking .md files, corrected 50/50 layout alignment for editor/preview panes
|
||||||
- **v1.3.0** - Major update: Tabbed interface for multiple files, enhanced PDF export with LaTeX engines, fixed file associations, removed redundant converter menu, improved UI architecture
|
- **v1.3.0** - Major update: Tabbed interface for multiple files, enhanced PDF export with LaTeX engines, fixed file associations, removed redundant converter menu, improved UI architecture
|
||||||
- **v1.2.1** - Comprehensive editor enhancements: Find & Replace, Line Numbers, Undo/Redo, Auto-indentation, PowerPoint export, document conversion menu, table creation helper, spreadsheet export
|
- **v1.2.1** - Comprehensive editor enhancements: Find & Replace, Line Numbers, Undo/Redo, Auto-indentation, PowerPoint export, document conversion menu, table creation helper, spreadsheet export
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 5.5 KiB |
+3
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pan-converter",
|
"name": "pan-converter",
|
||||||
"version": "1.5.3",
|
"version": "1.5.7",
|
||||||
"description": "Cross-platform Markdown editor and converter using Pandoc",
|
"description": "Cross-platform Markdown editor and converter using Pandoc",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -44,6 +44,7 @@
|
|||||||
"directories": {
|
"directories": {
|
||||||
"output": "dist"
|
"output": "dist"
|
||||||
},
|
},
|
||||||
|
"icon": "assets/icon",
|
||||||
"files": [
|
"files": [
|
||||||
"src/**/*",
|
"src/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
@@ -87,7 +88,7 @@
|
|||||||
],
|
],
|
||||||
"artifactName": "${productName}-${version}-${arch}.${ext}",
|
"artifactName": "${productName}-${version}-${arch}.${ext}",
|
||||||
"requestedExecutionLevel": "asInvoker",
|
"requestedExecutionLevel": "asInvoker",
|
||||||
"signAndEditExecutable": true
|
"signAndEditExecutable": false
|
||||||
},
|
},
|
||||||
"nsis": {
|
"nsis": {
|
||||||
"oneClick": false,
|
"oneClick": false,
|
||||||
|
|||||||
+39
-38
@@ -2,18 +2,19 @@ const { app, BrowserWindow, Menu, dialog, ipcMain, shell } = require('electron')
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
const XLSX = require('xlsx');
|
|
||||||
|
|
||||||
// Get the system Pandoc path
|
// Get the system Pandoc path
|
||||||
function getPandocPath() {
|
function getPandocPath() {
|
||||||
// Always use system pandoc - no bundled binaries
|
// Pandoc is expected to be in the system's PATH.
|
||||||
|
// The command will be executed directly. Quoting is handled by exec.
|
||||||
return 'pandoc';
|
return 'pandoc';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if Pandoc is available
|
// Check if Pandoc is available
|
||||||
function checkPandocAvailable() {
|
function checkPandocAvailable() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
exec('pandoc --version', (error) => {
|
const pandocPath = getPandocPath();
|
||||||
|
exec(`${pandocPath} --version`, (error) => {
|
||||||
resolve(!error);
|
resolve(!error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -181,7 +182,6 @@ function createMenu() {
|
|||||||
{ label: 'OpenDocument Presentation (ODP)', click: () => exportFile('odp') },
|
{ label: 'OpenDocument Presentation (ODP)', click: () => exportFile('odp') },
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{ label: 'CSV (Tables)', click: () => exportSpreadsheet('csv') },
|
{ label: 'CSV (Tables)', click: () => exportSpreadsheet('csv') },
|
||||||
{ label: 'XLSX (Tables)', click: () => exportSpreadsheet('xlsx') }
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
@@ -277,7 +277,7 @@ function createMenu() {
|
|||||||
type: 'info',
|
type: 'info',
|
||||||
title: 'About PanConverter',
|
title: 'About PanConverter',
|
||||||
message: 'PanConverter',
|
message: 'PanConverter',
|
||||||
detail: 'A cross-platform Markdown editor and converter using Pandoc.\n\nVersion: 1.5.0\nAuthor: Amit Haridas\nEmail: amit.wh@gmail.com\nLicense: MIT\n\nFeatures:\n• Windows Explorer context menu integration\n• Tabbed interface for multiple files\n• Advanced markdown editing with live preview\n• Enhanced PDF export with built-in Electron fallback\n• File association support for .md files\n• Command-line interface for batch conversion\n• Advanced export options with templates and metadata\n• Batch file conversion with progress tracking\n• Improved preview typography and spacing\n• Adjustable font sizes via menu (Ctrl+Shift+Plus/Minus)\n• Complete theme support including Monokai fixes\n• Find & replace with match highlighting\n• Line numbers and auto-indentation\n• Export to multiple formats via Pandoc\n• PowerPoint & presentation export\n• Export tables to Excel/ODS spreadsheets\n• Document import & conversion\n• Table creation helper\n• Multiple themes support\n• Undo/redo functionality\n• Live word count and statistics',
|
detail: 'A cross-platform Markdown editor and converter using Pandoc.\n\nVersion: 1.5.7\nAuthor: Amit Haridas\nEmail: amit.wh@gmail.com\nLicense: MIT\n\nFeatures:\n• Windows Explorer context menu integration\n• Tabbed interface for multiple files\n• Advanced markdown editing with live preview\n• Real-time preview updates while typing\n• Full toolbar markdown editing functions\n• Enhanced PDF export with built-in Electron fallback\n• File association support for .md files\n• Command-line interface for batch conversion\n• Advanced export options with templates and metadata\n• Batch file conversion with progress tracking\n• Improved preview typography and spacing\n• Adjustable font sizes via menu (Ctrl+Shift+Plus/Minus)\n• Complete theme support including Monokai fixes\n• Find & replace with match highlighting\n• Line numbers and auto-indentation\n• Export to multiple formats via Pandoc\n• PowerPoint & presentation export\n• Export tables to Excel/ODS spreadsheets\n• Document import & conversion\n• Table creation helper\n• Multiple themes support\n• Undo/redo functionality\n• Live word count and statistics',
|
||||||
buttons: ['OK']
|
buttons: ['OK']
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -416,12 +416,12 @@ function performExportWithOptions(format, options) {
|
|||||||
|
|
||||||
// Add specific options for PDF export to ensure proper generation
|
// Add specific options for PDF export to ensure proper generation
|
||||||
if (format === 'pdf') {
|
if (format === 'pdf') {
|
||||||
const pdfEngine = options.pdfEngine || 'xelatex';
|
const pdfEngine = options.pdfEngine || 'xelatex'; // Default to xelatex
|
||||||
const geometry = options.geometry || 'margin=1in';
|
pandocCmd += ` --pdf-engine="${pdfEngine}"`;
|
||||||
pandocCmd += ` --pdf-engine=${pdfEngine} -V geometry:${geometry}`;
|
if (options.geometry) pandocCmd += ` -V geometry:"${options.geometry}"`;
|
||||||
|
|
||||||
// Try with specified PDF engine
|
// Try with specified PDF engine
|
||||||
exec(pandocCmd, (error, stdout, stderr) => {
|
exec(pandocCmd, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
// Try fallback engines if the specified one fails
|
// Try fallback engines if the specified one fails
|
||||||
const fallbackEngines = ['pdflatex', 'lualatex'];
|
const fallbackEngines = ['pdflatex', 'lualatex'];
|
||||||
@@ -431,13 +431,7 @@ function performExportWithOptions(format, options) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (format === 'docx') {
|
} else if (format === 'docx') {
|
||||||
pandocCmd = `${getPandocPath()} "${currentFile}" -t docx -o "${outputFile}"`;
|
pandocCmd += ' -t docx';
|
||||||
exportWithPandoc(pandocCmd, outputFile, format);
|
|
||||||
} else if (format === 'html') {
|
|
||||||
pandocCmd = `${getPandocPath()} "${currentFile}" -t html5 --standalone -o "${outputFile}"`;
|
|
||||||
exportWithPandoc(pandocCmd, outputFile, format);
|
|
||||||
} else if (format === 'latex') {
|
|
||||||
pandocCmd = `${getPandocPath()} "${currentFile}" -t latex -o "${outputFile}"`;
|
|
||||||
exportWithPandoc(pandocCmd, outputFile, format);
|
exportWithPandoc(pandocCmd, outputFile, format);
|
||||||
} else {
|
} else {
|
||||||
// Generic export for other formats
|
// Generic export for other formats
|
||||||
@@ -462,9 +456,10 @@ function tryPdfFallback(inputFile, outputFile, engines, index, options, lastErro
|
|||||||
}
|
}
|
||||||
|
|
||||||
const engine = engines[index];
|
const engine = engines[index];
|
||||||
const geometry = options.geometry || 'margin=1in';
|
|
||||||
let pandocCmd = `${getPandocPath()} "${inputFile}" --pdf-engine=${engine} -V geometry:${geometry} -o "${outputFile}"`;
|
let pandocCmd = `${getPandocPath()} "${inputFile}" --pdf-engine=${engine} -V geometry:${geometry} -o "${outputFile}"`;
|
||||||
|
|
||||||
|
if (options.geometry) pandocCmd += ` -V geometry:"${options.geometry}"`;
|
||||||
|
|
||||||
// Add all other options
|
// Add all other options
|
||||||
if (options.template && options.template !== 'default') {
|
if (options.template && options.template !== 'default') {
|
||||||
pandocCmd += ` --template="${options.template}"`;
|
pandocCmd += ` --template="${options.template}"`;
|
||||||
@@ -478,7 +473,7 @@ function tryPdfFallback(inputFile, outputFile, engines, index, options, lastErro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exec(pandocCmd, (error, stdout, stderr) => {
|
exec(pandocCmd, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
tryPdfFallback(inputFile, outputFile, engines, index + 1, options, error);
|
tryPdfFallback(inputFile, outputFile, engines, index + 1, options, error);
|
||||||
} else {
|
} else {
|
||||||
@@ -498,16 +493,35 @@ function showExportSuccess(outputFile) {
|
|||||||
|
|
||||||
// Helper function to export with pandoc (general)
|
// Helper function to export with pandoc (general)
|
||||||
function exportWithPandoc(pandocCmd, outputFile, format) {
|
function exportWithPandoc(pandocCmd, outputFile, format) {
|
||||||
|
console.log(`Executing Pandoc command: ${pandocCmd}`);
|
||||||
|
|
||||||
exec(pandocCmd, (error, stdout, stderr) => {
|
exec(pandocCmd, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(`Pandoc error for ${format}:`, error);
|
console.error(`Pandoc error for ${format}:`, error);
|
||||||
dialog.showErrorBox('Export Error',
|
console.error(`Pandoc stderr:`, stderr);
|
||||||
`Failed to export to ${format.toUpperCase()}:\n${error.message}\n\n` +
|
console.error(`Pandoc stdout:`, stdout);
|
||||||
`Command used: ${pandocCmd}\n\n` +
|
|
||||||
`Please ensure Pandoc is properly installed and accessible.`
|
// Provide more specific error messages
|
||||||
);
|
let errorMessage = `Failed to export to ${format.toUpperCase()}`;
|
||||||
|
|
||||||
|
if (error.message.includes('not found') || error.message.includes('not recognized')) {
|
||||||
|
errorMessage += '\n\nPandoc is not installed or not found in PATH.';
|
||||||
|
errorMessage += '\nPlease install Pandoc from: https://pandoc.org/installing.html';
|
||||||
|
} else if (stderr) {
|
||||||
|
errorMessage += `\n\nError details: ${stderr}`;
|
||||||
|
} else {
|
||||||
|
errorMessage += `\n\nError details: ${error.message}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorMessage += `\n\nCommand used: ${pandocCmd}`;
|
||||||
|
|
||||||
|
dialog.showErrorBox('Export Error', errorMessage);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Successfully exported to ${format}:`, outputFile);
|
console.log(`Successfully exported to ${format}:`, outputFile);
|
||||||
|
console.log(`Pandoc stdout:`, stdout);
|
||||||
|
if (stderr) {
|
||||||
|
console.warn(`Pandoc stderr (non-fatal):`, stderr);
|
||||||
|
}
|
||||||
showExportSuccess(outputFile);
|
showExportSuccess(outputFile);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -878,20 +892,7 @@ ipcMain.on('export-spreadsheet', (event, { content, format }) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Write CSV file
|
|
||||||
fs.writeFileSync(outputFile, csvContent, 'utf-8');
|
fs.writeFileSync(outputFile, csvContent, 'utf-8');
|
||||||
} else if (format === 'xlsx') {
|
|
||||||
// Convert tables to XLSX format
|
|
||||||
const workbook = XLSX.utils.book_new();
|
|
||||||
|
|
||||||
tables.forEach((table, index) => {
|
|
||||||
const sheetName = tables.length > 1 ? `Table${index + 1}` : 'Table';
|
|
||||||
const worksheet = XLSX.utils.aoa_to_sheet(table);
|
|
||||||
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Write XLSX file
|
|
||||||
XLSX.writeFile(workbook, outputFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog.showMessageBox(mainWindow, {
|
dialog.showMessageBox(mainWindow, {
|
||||||
@@ -1054,8 +1055,8 @@ function performBatchConversion(inputFolder, outputFolder, format, options) {
|
|||||||
// Add PDF-specific options
|
// Add PDF-specific options
|
||||||
if (format === 'pdf') {
|
if (format === 'pdf') {
|
||||||
const pdfEngine = options.pdfEngine || 'xelatex';
|
const pdfEngine = options.pdfEngine || 'xelatex';
|
||||||
const geometry = options.geometry || 'margin=1in';
|
pandocCmd += ` --pdf-engine="${pdfEngine}"`;
|
||||||
pandocCmd += ` --pdf-engine=${pdfEngine} -V geometry:${geometry}`;
|
if (options.geometry) pandocCmd += ` -V geometry:"${options.geometry}"`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute conversion
|
// Execute conversion
|
||||||
|
|||||||
+147
-23
@@ -139,6 +139,14 @@ class TabManager {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
document.querySelector('.editor-container').appendChild(tabContent);
|
document.querySelector('.editor-container').appendChild(tabContent);
|
||||||
|
|
||||||
|
// Directly attach input listener to the new editor
|
||||||
|
const editor = document.getElementById(`editor-${tab.id}`);
|
||||||
|
if (editor) {
|
||||||
|
editor.addEventListener('input', () => {
|
||||||
|
this.handleEditorInput(tab.id);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switchToTab(tabId) {
|
switchToTab(tabId) {
|
||||||
@@ -376,24 +384,22 @@ class TabManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setupEditorEvents() {
|
setupEditorEvents() {
|
||||||
// Set up editor events using event delegation
|
// Set up editor events using event delegation on the container
|
||||||
document.addEventListener('input', (e) => {
|
const editorContainer = document.querySelector('.editor-container');
|
||||||
if (e.target.classList.contains('editor-textarea')) {
|
if (editorContainer) {
|
||||||
const tabId = parseInt(e.target.id.split('-')[1]);
|
editorContainer.addEventListener('input', (e) => {
|
||||||
if (tabId === this.activeTabId) {
|
if (e.target.classList.contains('editor-textarea')) {
|
||||||
|
const tabId = parseInt(e.target.id.split('-')[1]);
|
||||||
this.handleEditorInput(tabId);
|
this.handleEditorInput(tabId);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
document.addEventListener('scroll', (e) => {
|
editorContainer.addEventListener('scroll', (e) => {
|
||||||
if (e.target.classList.contains('editor-textarea')) {
|
if (e.target.classList.contains('editor-textarea')) {
|
||||||
const tabId = parseInt(e.target.id.split('-')[1]);
|
|
||||||
if (tabId === this.activeTabId) {
|
|
||||||
this.updateLineNumbers();
|
this.updateLineNumbers();
|
||||||
}
|
}
|
||||||
}
|
}, true);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEditorInput(tabId) {
|
handleEditorInput(tabId) {
|
||||||
@@ -401,6 +407,8 @@ class TabManager {
|
|||||||
if (!tab) return;
|
if (!tab) return;
|
||||||
|
|
||||||
const editor = document.getElementById(`editor-${tabId}`);
|
const editor = document.getElementById(`editor-${tabId}`);
|
||||||
|
if (!editor) return;
|
||||||
|
|
||||||
tab.content = editor.value;
|
tab.content = editor.value;
|
||||||
tab.isDirty = true;
|
tab.isDirty = true;
|
||||||
|
|
||||||
@@ -517,7 +525,7 @@ class TabManager {
|
|||||||
|
|
||||||
// Save to localStorage and sync with main process
|
// Save to localStorage and sync with main process
|
||||||
localStorage.setItem('recentFiles', JSON.stringify(this.recentFiles));
|
localStorage.setItem('recentFiles', JSON.stringify(this.recentFiles));
|
||||||
window.electronAPI.send('save-recent-files', this.recentFiles);
|
ipcRenderer.send('save-recent-files', this.recentFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
getRecentFiles() {
|
getRecentFiles() {
|
||||||
@@ -532,18 +540,121 @@ class TabManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setupToolbarEvents() {
|
setupToolbarEvents() {
|
||||||
// Existing toolbar setup...
|
// Bold
|
||||||
|
document.getElementById('btn-bold').addEventListener('click', () => {
|
||||||
|
this.wrapSelection('**', '**');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Italic
|
||||||
|
document.getElementById('btn-italic').addEventListener('click', () => {
|
||||||
|
this.wrapSelection('*', '*');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Heading
|
||||||
|
document.getElementById('btn-heading').addEventListener('click', () => {
|
||||||
|
this.insertAtLineStart('## ');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Link
|
||||||
|
document.getElementById('btn-link').addEventListener('click', () => {
|
||||||
|
this.wrapSelection('[', '](url)');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Code
|
||||||
|
document.getElementById('btn-code').addEventListener('click', () => {
|
||||||
|
this.wrapSelection('`', '`');
|
||||||
|
});
|
||||||
|
|
||||||
|
// List
|
||||||
|
document.getElementById('btn-list').addEventListener('click', () => {
|
||||||
|
this.insertAtLineStart('- ');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Quote
|
||||||
|
document.getElementById('btn-quote').addEventListener('click', () => {
|
||||||
|
this.insertAtLineStart('> ');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Table
|
||||||
|
document.getElementById('btn-table').addEventListener('click', () => {
|
||||||
|
this.insertTable();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Preview toggle
|
||||||
document.getElementById('btn-preview-toggle').addEventListener('click', () => {
|
document.getElementById('btn-preview-toggle').addEventListener('click', () => {
|
||||||
this.isPreviewVisible = !this.isPreviewVisible;
|
this.isPreviewVisible = !this.isPreviewVisible;
|
||||||
this.updatePreviewVisibility();
|
this.updatePreviewVisibility();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Line numbers
|
||||||
document.getElementById('btn-line-numbers').addEventListener('click', () => {
|
document.getElementById('btn-line-numbers').addEventListener('click', () => {
|
||||||
this.showLineNumbers = !this.showLineNumbers;
|
this.showLineNumbers = !this.showLineNumbers;
|
||||||
this.updateLineNumbers();
|
this.updateLineNumbers();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Add other toolbar events...
|
// Helper function to wrap selected text
|
||||||
|
wrapSelection(before, after) {
|
||||||
|
const editor = document.getElementById(`editor-${this.activeTabId}`);
|
||||||
|
if (!editor) return;
|
||||||
|
|
||||||
|
const start = editor.selectionStart;
|
||||||
|
const end = editor.selectionEnd;
|
||||||
|
const selectedText = editor.value.substring(start, end);
|
||||||
|
const replacement = before + (selectedText || 'text') + after;
|
||||||
|
|
||||||
|
editor.value = editor.value.substring(0, start) + replacement + editor.value.substring(end);
|
||||||
|
|
||||||
|
// Update cursor position
|
||||||
|
const newCursorPos = selectedText ? start + replacement.length : start + before.length;
|
||||||
|
editor.selectionStart = editor.selectionEnd = newCursorPos;
|
||||||
|
editor.focus();
|
||||||
|
|
||||||
|
// Trigger update
|
||||||
|
this.handleEditorInput(this.activeTabId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to insert text at the start of current line
|
||||||
|
insertAtLineStart(prefix) {
|
||||||
|
const editor = document.getElementById(`editor-${this.activeTabId}`);
|
||||||
|
if (!editor) return;
|
||||||
|
|
||||||
|
const start = editor.selectionStart;
|
||||||
|
const text = editor.value;
|
||||||
|
|
||||||
|
// Find the start of the current line
|
||||||
|
let lineStart = text.lastIndexOf('\n', start - 1) + 1;
|
||||||
|
|
||||||
|
// Insert the prefix
|
||||||
|
editor.value = text.substring(0, lineStart) + prefix + text.substring(lineStart);
|
||||||
|
|
||||||
|
// Update cursor position
|
||||||
|
editor.selectionStart = editor.selectionEnd = start + prefix.length;
|
||||||
|
editor.focus();
|
||||||
|
|
||||||
|
// Trigger update
|
||||||
|
this.handleEditorInput(this.activeTabId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert a markdown table
|
||||||
|
insertTable() {
|
||||||
|
const editor = document.getElementById(`editor-${this.activeTabId}`);
|
||||||
|
if (!editor) return;
|
||||||
|
|
||||||
|
const table = '\n| Column 1 | Column 2 | Column 3 |\n' +
|
||||||
|
'|----------|----------|----------|\n' +
|
||||||
|
'| Cell 1 | Cell 2 | Cell 3 |\n' +
|
||||||
|
'| Cell 4 | Cell 5 | Cell 6 |\n';
|
||||||
|
|
||||||
|
const start = editor.selectionStart;
|
||||||
|
editor.value = editor.value.substring(0, start) + table + editor.value.substring(start);
|
||||||
|
|
||||||
|
// Update cursor position
|
||||||
|
editor.selectionStart = editor.selectionEnd = start + table.length;
|
||||||
|
editor.focus();
|
||||||
|
|
||||||
|
// Trigger update
|
||||||
|
this.handleEditorInput(this.activeTabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
setupFindEvents() {
|
setupFindEvents() {
|
||||||
@@ -562,10 +673,13 @@ class TabManager {
|
|||||||
openFile(filePath, content) {
|
openFile(filePath, content) {
|
||||||
let tab = this.tabs.get(this.activeTabId);
|
let tab = this.tabs.get(this.activeTabId);
|
||||||
|
|
||||||
|
// Handle both forward and back slashes for cross-platform compatibility
|
||||||
|
const fileName = filePath.split(/[\\/]/).pop();
|
||||||
|
|
||||||
// If current tab is empty and untitled, reuse it
|
// If current tab is empty and untitled, reuse it
|
||||||
if (!tab.filePath && !tab.isDirty && tab.content === '') {
|
if (!tab.filePath && !tab.isDirty && tab.content === '') {
|
||||||
tab.filePath = filePath;
|
tab.filePath = filePath;
|
||||||
tab.title = filePath.split('/').pop();
|
tab.title = fileName;
|
||||||
tab.content = content;
|
tab.content = content;
|
||||||
tab.originalContent = content;
|
tab.originalContent = content;
|
||||||
tab.isDirty = false;
|
tab.isDirty = false;
|
||||||
@@ -574,7 +688,7 @@ class TabManager {
|
|||||||
this.createNewTab();
|
this.createNewTab();
|
||||||
tab = this.tabs.get(this.activeTabId);
|
tab = this.tabs.get(this.activeTabId);
|
||||||
tab.filePath = filePath;
|
tab.filePath = filePath;
|
||||||
tab.title = filePath.split('/').pop();
|
tab.title = fileName;
|
||||||
tab.content = content;
|
tab.content = content;
|
||||||
tab.originalContent = content;
|
tab.originalContent = content;
|
||||||
tab.isDirty = false;
|
tab.isDirty = false;
|
||||||
@@ -603,6 +717,14 @@ let tabManager;
|
|||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
tabManager = new TabManager();
|
tabManager = new TabManager();
|
||||||
|
|
||||||
|
// Attach input listener to the initial editor (tab 1)
|
||||||
|
const initialEditor = document.getElementById('editor-1');
|
||||||
|
if (initialEditor) {
|
||||||
|
initialEditor.addEventListener('input', () => {
|
||||||
|
tabManager.handleEditorInput(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Request current theme
|
// Request current theme
|
||||||
ipcRenderer.send('get-theme');
|
ipcRenderer.send('get-theme');
|
||||||
|
|
||||||
@@ -626,7 +748,9 @@ ipcRenderer.on('file-new', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on('file-opened', (event, data) => {
|
ipcRenderer.on('file-opened', (event, data) => {
|
||||||
tabManager.openFile(data.path, data.content);
|
if (tabManager) {
|
||||||
|
tabManager.openFile(data.path, data.content);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on('file-save', () => {
|
ipcRenderer.on('file-save', () => {
|
||||||
@@ -1110,13 +1234,13 @@ if (originalExportConfirm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IPC event listeners for recent files functionality
|
// IPC event listeners for recent files functionality
|
||||||
if (window.electronAPI) {
|
ipcRenderer.on('recent-files-cleared', () => {
|
||||||
window.electronAPI.on('recent-files-cleared', () => {
|
if (tabManager) {
|
||||||
tabManager.recentFiles = [];
|
tabManager.recentFiles = [];
|
||||||
localStorage.setItem('recentFiles', JSON.stringify([]));
|
localStorage.setItem('recentFiles', JSON.stringify([]));
|
||||||
console.log('Recent files cleared');
|
console.log('Recent files cleared');
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
// Add math rendering support using KaTeX for enhanced preview
|
// Add math rendering support using KaTeX for enhanced preview
|
||||||
function initMathSupport() {
|
function initMathSupport() {
|
||||||
|
|||||||
Reference in New Issue
Block a user