diff --git a/package.json b/package.json index d96d5bb..fd71d96 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "swordfish", "productName": "Swordfish", - "version": "5.6.4", + "version": "5.6.5", "description": "Swordfish Translation Editor", "main": "js/Swordfish.js", "scripts": { @@ -20,7 +20,7 @@ "url": "https://github.com/rmraya/Swordfish.git" }, "devDependencies": { - "electron": "^32.1.0", + "electron": "^32.1.2", "typescript": "^5.6.2" }, "dependencies": { diff --git a/src/com/maxprograms/swordfish/Constants.java b/src/com/maxprograms/swordfish/Constants.java index d30556d..a42b172 100644 --- a/src/com/maxprograms/swordfish/Constants.java +++ b/src/com/maxprograms/swordfish/Constants.java @@ -20,7 +20,7 @@ private Constants() { public static final String APPNAME = "Swordfish"; public static final String VERSION = "5.6.4"; - public static final String BUILD = "20240916_1202"; + public static final String BUILD = "20240921_0931"; public static final String REASON = "reason"; public static final String STATUS = "status"; diff --git a/ts/Main.ts b/ts/Main.ts index 6d03faf..e915810 100644 --- a/ts/Main.ts +++ b/ts/Main.ts @@ -404,7 +404,13 @@ class Main { let html: string = clipboardData.getData('text/html'); if (html.length !== 0) { event.preventDefault(); - this.parseClipboardHtml(html); + if (this.hasTags(html)) { + this.parseClipboardHtml(html); + } else { + let text = clipboardData.getData('text/plain').replace(/\r/g, ''); + text = text.replace(/\n\n/g, '\n'); + document.execCommand('insertHTML', false, text); + } } }); @@ -413,6 +419,21 @@ class Main { }, 200); } + hasTags(html: string): boolean { + let container: HTMLDivElement = document.createElement('div'); + container.innerHTML = html; + let tags: NodeListOf = container.querySelectorAll('img'); + if (tags.length > 0) { + for (let i = 0; i < tags.length; i++) { + let img: HTMLImageElement = tags[i] as HTMLImageElement; + if (img.getAttribute('data-ref') && img.getAttribute('src').endsWith('.svg')) { + return true; + } + } + } + return false; + } + parseClipboardHtml(html: string): void { let container: HTMLDivElement = document.createElement('div'); container.innerHTML = html; @@ -446,13 +467,15 @@ class Main { return ''; } if (node.nodeType === Node.TEXT_NODE) { - let content = node.textContent.replace(/\n/g, ' '); - result += content; - result = result.replace(/\s\s+/g, ' '); + let content = node.textContent.replace(/\n/g, ''); + return content; } node.childNodes.forEach((child) => { result += this.recurseNodes(child); }); + if (node.nodeName === 'DIV') { + return result.trim(); + } return result; } diff --git a/ts/Swordfish.ts b/ts/Swordfish.ts index f417e74..b71c43b 100644 --- a/ts/Swordfish.ts +++ b/ts/Swordfish.ts @@ -523,10 +523,6 @@ export class Swordfish { ipcMain.on('get-segments', (event: IpcMainEvent, arg: any) => { Swordfish.getSegmenst(event, arg); }); - ipcMain.on('paste-tag', (event: IpcMainEvent, arg: any) => { - clipboard.writeHTML(arg); - Swordfish.mainWindow.webContents.paste(); - }); ipcMain.on('paste-text', (event: IpcMainEvent, arg: any) => { clipboard.writeText(arg); Swordfish.mainWindow.webContents.paste(); @@ -1844,7 +1840,7 @@ export class Swordfish { } static getSelectedFiles(event: IpcMainEvent): void { - if (Swordfish.selectedFiles.length > 0) { + if (Swordfish.selectedFiles?.length > 0) { Swordfish.getFileType(event, Swordfish.selectedFiles); Swordfish.selectedFiles = []; } diff --git a/ts/translation.ts b/ts/translation.ts index e267e00..b59e2a6 100644 --- a/ts/translation.ts +++ b/ts/translation.ts @@ -1527,7 +1527,8 @@ class TranslationView { if (targetTags.has(tag)) { this.removeTag(tag); } - this.electron.ipcRenderer.send('paste-tag', this.sourceTags.get(tag)); + let svg: string = this.sourceTags.get(tag) + document.execCommand('insertHTML', false, svg); } } else { this.electron.ipcRenderer.send('show-tag-window'); @@ -1797,17 +1798,15 @@ class TranslationView { } } if (tags !== '') { - this.electron.ipcRenderer.send('paste-tag', tags); + document.execCommand('insertHTML', false, tags); } } removeTags(): void { let target: HTMLTableCellElement = this.currentRow.getElementsByClassName('target')[0] as HTMLTableCellElement; - let targetTags = this.getTags(target); - for (let key of this.sourceTags.keys()) { - if (targetTags.has(key)) { - this.removeTag(key.valueOf()); - } + let tags: NodeListOf = target.querySelectorAll('img'); + for (let i = 0; i < tags.length; i++) { + target.removeChild(tags[i]); } }