Skip to content

Commit

Permalink
Updated for release 5.6.5
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Sep 23, 2024
1 parent d3678a2 commit 7ae8b14
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/com/maxprograms/swordfish/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
31 changes: 27 additions & 4 deletions ts/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});

Expand All @@ -413,6 +419,21 @@ class Main {
}, 200);
}

hasTags(html: string): boolean {
let container: HTMLDivElement = document.createElement('div');
container.innerHTML = html;
let tags: NodeListOf<Element> = 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;
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 1 addition & 5 deletions ts/Swordfish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 = [];
}
Expand Down
13 changes: 6 additions & 7 deletions ts/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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<Element> = target.querySelectorAll('img');
for (let i = 0; i < tags.length; i++) {
target.removeChild(tags[i]);
}
}

Expand Down

0 comments on commit 7ae8b14

Please sign in to comment.