aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2017-12-21 14:41:36 +0100
committerLibravatar GitHub <noreply@github.com>2017-12-21 14:41:36 +0100
commit845901382d6356a45c1107ac4ef26df769d2965c (patch)
tree32b701de50c505abc95ceddc7c429df85c81f041
parentMerge pull request #475 from meetfranz/feature/service-improvements (diff)
parentMerge branch 'develop' into feature/macOS-copy-paste (diff)
downloadferdium-app-845901382d6356a45c1107ac4ef26df769d2965c.tar.gz
ferdium-app-845901382d6356a45c1107ac4ef26df769d2965c.tar.zst
ferdium-app-845901382d6356a45c1107ac4ef26df769d2965c.zip
Merge pull request #466 from meetfranz/feature/macOS-copy-paste
[PR] macOS copy paste
-rw-r--r--src/helpers/webview-ime-focus-helpers.js38
-rw-r--r--src/webview/ime.js10
-rw-r--r--src/webview/plugin.js1
3 files changed, 0 insertions, 49 deletions
diff --git a/src/helpers/webview-ime-focus-helpers.js b/src/helpers/webview-ime-focus-helpers.js
deleted file mode 100644
index 2593a5f26..000000000
--- a/src/helpers/webview-ime-focus-helpers.js
+++ /dev/null
@@ -1,38 +0,0 @@
1module.exports.releaseDocumentFocus = () => {
2 const element = document.createElement('span');
3 document.body.appendChild(element);
4
5 const range = document.createRange();
6 range.setStart(element, 0);
7
8 const selection = window.getSelection();
9 selection.removeAllRanges();
10 selection.addRange(range);
11 selection.removeAllRanges();
12
13 document.body.removeChild(element);
14};
15
16module.exports.claimDocumentFocus = () => {
17 const { activeElement } = document;
18 const selection = window.getSelection();
19
20 let selectionStart;
21 let selectionEnd;
22 let range;
23
24 if (activeElement) ({ selectionStart, selectionEnd } = activeElement);
25 if (selection.rangeCount) range = selection.getRangeAt(0);
26
27 const restoreOriginalSelection = () => {
28 if (selectionStart >= 0 && selectionEnd >= 0) {
29 activeElement.selectionStart = selectionStart;
30 activeElement.selectionEnd = selectionEnd;
31 } else if (range) {
32 selection.addRange(range);
33 }
34 };
35
36 exports.releaseDocumentFocus();
37 window.requestAnimationFrame(restoreOriginalSelection);
38};
diff --git a/src/webview/ime.js b/src/webview/ime.js
deleted file mode 100644
index 43df6267c..000000000
--- a/src/webview/ime.js
+++ /dev/null
@@ -1,10 +0,0 @@
1const { ipcRenderer } = require('electron');
2const { claimDocumentFocus } = require('../helpers/webview-ime-focus-helpers');
3
4ipcRenderer.on('claim-document-focus', claimDocumentFocus);
5
6window.addEventListener('DOMContentLoaded', () => {
7 if (document.querySelector('[autofocus]')) {
8 ipcRenderer.sendToHost('autofocus');
9 }
10});
diff --git a/src/webview/plugin.js b/src/webview/plugin.js
index cf38169d3..9903ee07a 100644
--- a/src/webview/plugin.js
+++ b/src/webview/plugin.js
@@ -7,7 +7,6 @@ import RecipeWebview from './lib/RecipeWebview';
7 7
8import Spellchecker from './spellchecker.js'; 8import Spellchecker from './spellchecker.js';
9import './notifications.js'; 9import './notifications.js';
10import './ime.js';
11 10
12ipcRenderer.on('initializeRecipe', (e, data) => { 11ipcRenderer.on('initializeRecipe', (e, data) => {
13 const modulePath = path.join(data.recipe.path, 'webview.js'); 12 const modulePath = path.join(data.recipe.path, 'webview.js');