-
Notifications
You must be signed in to change notification settings - Fork 25
/
evil-collection-webkit.el
110 lines (93 loc) · 3.37 KB
/
evil-collection-webkit.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
;;; evil-collection-webkit.el --- Evil bindings for webkit -*- lexical-binding: t -*-
;; Copyright (C) 2020 Akira Kyle
;; Author: Akira Kyle <[email protected]>
;; Maintainer: Akira Kyle <[email protected]>
;; URL: https://github.com/emacs-evil/evil-collection
;; Version: 0.0.1
;; Package-Requires: ((emacs "25.1"))
;; Keywords: evil, webkit, tools
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 3, or (at your
;; option) any later version.
;;
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; For a full copy of the GNU General Public License
;; see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Evil bindings for webkit.
;;; Code:
(require 'webkit)
(require 'evil-collection)
(defvar evil-collection-webkit-maps '(webkit-mode-map))
(defun webkit-scroll-up-half (&optional webkit-id)
(interactive)
(webkit-scroll-by-percent 0.5 webkit-id))
(defun webkit-scroll-down-half (&optional webkit-id)
(interactive)
(webkit-scroll-by-percent -0.5 webkit-id))
(defvar webkit--evil-escape-script "
function WKViewEvilKeyDown(event) {
console.log('WKViewKeyDown: '+event.key);
if (event.key == 'Escape') {
window.webkit.messageHandlers['webkit--callback-unfocus'].postMessage('');
}
}
document.addEventListener('keydown', WKViewEvilKeyDown);
")
(defun evil-collection-webkit-escape ()
(webkit-add-script webkit--evil-escape-script))
(defun evil-collection-webkit-insert-on-insert ()
(add-hook 'evil-insert-state-entry-hook 'webkit-insert-mode nil t))
(defun evil-collection-webkit-unfocus-to-normal-mode (val)
(ignore val)
(evil-normal-state))
;;;###autoload
(defun evil-collection-xwidget-setup ()
"Set up `evil' bindings for `webkit'."
(evil-collection-define-key 'normal 'webkit-mode-map
"q" 'quit-window
"k" 'webkit-scroll-down-line
"j" 'webkit-scroll-up-line
"h" 'webkit-scroll-backward
"l" 'webkit-scroll-forward
"d" 'webkit-scroll-up-half
"u" 'webkit-scroll-down-half
(kbd "C-f") 'webkit-scroll-up
(kbd "C-b") 'webkit-scroll-down
"+" 'webkit-zoom-in
"=" 'webkit-zoom-in
"-" 'webkit-zoom-out
"f" 'webkit-ace
"/" 'webkit-isearch
"n" 'webkit-search-next
"N" 'webkit-search-previous
"ESC" 'webkit-search-finish
"R" 'webkit-reload
"gr" 'webkit-reload
"H" 'webkit-back
"L" 'webkit-forward
"gu" 'webkit
"gg" 'webkit-scroll-top
"G" 'webkit-scroll-bottom
"y" 'webkit-copy-selection
"Y" 'webkit-copy-url
"zd" 'webkit-dark-toggle)
(when evil-want-C-d-scroll
(evil-collection-define-key 'normal 'webkit-mode-map
(kbd "C-d") 'webkit-scroll-up-half))
(when evil-want-C-u-scroll
(evil-collection-define-key 'normal 'webkit-mode-map
(kbd "C-u") 'webkit-scroll-down-half))
(add-hook 'webkit-mode-hook #'evil-collection-webkit-insert-on-insert)
(add-hook 'webkit-new-hook #'evil-collection-webkit-escape)
(advice-add 'webkit--callback-unfocus
:after #'evil-collection-webkit-unfocus-to-normal-mode)
)
;; add advice around to go back to normal mode
(provide 'evil-collection-webkit)
;;; evil-collection-webkit.el ends here