Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

1import Foundation
2import Capacitor
3import SwiftUI
4
5@objc(LiquidTabsPlugin)
6public class LiquidTabsPlugin: CAPPlugin, CAPBridgedPlugin {
7 // So SwiftUI can notify JS
8 static weak var shared: LiquidTabsPlugin?
9
10 private let store = LiquidTabsStore.shared
11
12 public let identifier = "LiquidTabsPlugin"
13 public let jsName = "LiquidTabsPlugin"
14 public let pluginMethods: [CAPPluginMethod] = [
15 CAPPluginMethod(name: "configureTabs", returnType: CAPPluginReturnPromise),
16 CAPPluginMethod(name: "selectTab", returnType: CAPPluginReturnPromise)
17 ]
18
19 public override func load() {
20 super.load()
21 LiquidTabsPlugin.shared = self
22 }
23
24 // MARK: - Methods from JS
25
26 /// Configure tabs from JS.
27 /// Expected args:
28 /// { tabs: [{ id, title, systemImage, role }] }
…lines 29–75 unchanged (47 lines)
76 notifyListeners("tabSelected", data: ["id": id])
77 }
78
79 func notifySearchChanged(query: String) {
80 notifyListeners("searchChanged", data: ["query": query])
81 }
82}
83

After

1import Foundation
2import Capacitor
3import SwiftUI
4import WebKit
5
6@objc(LiquidTabsPlugin)
7public class LiquidTabsPlugin: CAPPlugin, CAPBridgedPlugin {
8 // So SwiftUI can notify JS
9 static weak var shared: LiquidTabsPlugin?
10
11 private let store = LiquidTabsStore.shared
12 private var keyboardHackScriptInstalled = false
13 private let keyboardHackHandlerName = "keyboardHackKey"
14
15 public let identifier = "LiquidTabsPlugin"
16 public let jsName = "LiquidTabsPlugin"
17 public let pluginMethods: [CAPPluginMethod] = [
18 CAPPluginMethod(name: "configureTabs", returnType: CAPPluginReturnPromise),
19 CAPPluginMethod(name: "selectTab", returnType: CAPPluginReturnPromise)
20 ]
21
22 public override func load() {
23 super.load()
24 LiquidTabsPlugin.shared = self
25 installKeyboardHackScript()
26 }
27
28 // MARK: - Methods from JS
29
30 /// Configure tabs from JS.
31 /// Expected args:
…lines 32–80 unchanged (49 lines)
81 }
82
83 func notifySearchChanged(query: String) {
84 notifyListeners("searchChanged", data: ["query": query])
85 }
86
87 func notifyKeyboardHackKey(key: String) {
88 notifyListeners("keyboardHackKey", data: ["key": key])
89 }
90
91 private func installKeyboardHackScript() {
92 guard !keyboardHackScriptInstalled,
93 let controller = bridge?.webView?.configuration.userContentController else {
94 return
95 }
96
97 keyboardHackScriptInstalled = true
98 controller.removeScriptMessageHandler(forName: keyboardHackHandlerName)
99 controller.add(self, name: keyboardHackHandlerName)
100
101 let source = """
102 (function() {
103 if (window.__logseqKeyboardHackInstalled) return;
104 window.__logseqKeyboardHackInstalled = true;
105 window.addEventListener('keydown', function(e) {
106 var k = null;
107 switch (e.key) {
108 case 'Backspace':
109 k = 'backspace';
110 break;
111 case 'Enter':
112 case 'Return':
113 k = 'enter';
114 break;
115 default:
116 if (e.keyCode === 8) k = 'backspace';
117 else if (e.keyCode === 13) k = 'enter';
118 break;
119 }
120 if (!k) return;
121 try {
122 window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.\(keyboardHackHandlerName).postMessage({ key: k });
123 } catch (_) {}
124 }, true);
125 })();
126 """
127
128 let script = WKUserScript(source: source, injectionTime: .atDocumentStart, forMainFrameOnly: false)
129 controller.addUserScript(script)
130 }
131}
132
133extension LiquidTabsPlugin: WKScriptMessageHandler {
134 public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
135 guard message.name == keyboardHackHandlerName else { return }
136
137 if let body = message.body as? [String: Any],
138 let key = body["key"] as? String {
139 notifyKeyboardHackKey(key: key)
140 }
141 }
142}
143

Before

source_file
import_declaration
import "import"
identifier
simple_identifier "Foundation"
import_declaration
import "import"
identifier
simple_identifier "Capacitor"
import_declaration
import "import"
identifier
simple_identifier "SwiftUI"
class_declaration
modifiers
attribute
@ "@"
user_type
type_identifier "objc"
( "("
simple_identifier "LiquidTabsPlugin"
) ")"
visibility_modifier
public "public"
class "class"
type_identifier "LiquidTabsPlugin"
: ":"
inheritance_specifier
user_type
type_identifier "CAPPlugin"
, ","
inheritance_specifier
user_type
type_identifier "CAPBridgedPlugin"
class_body
{ "{"
comment "// So SwiftUI can notify JS"
property_declaration
modifiers
property_modifier
static "static"
ownership_modifier
weak "weak"
value_binding_pattern
var "var"
pattern
simple_identifier "shared"
type_annotation
: ":"
optional_type
user_type
type_identifier "LiquidTabsPlugin"
?
? "?"
property_declaration
modifiers
visibility_modifier
private "private"
value_binding_pattern
let "let"
pattern
simple_identifier "store"
= "="
navigation_expression
simple_identifier "LiquidTabsStore"
navigation_suffix
. "."
simple_identifier "shared"
property_declaration
modifiers
visibility_modifier
public "public"
value_binding_pattern
let "let"
pattern
simple_identifier "identifier"
= "="
line_string_literal
" "\""
line_str_text "LiquidTabsPlugin"
" "\""
property_declaration
modifiers
visibility_modifier
public "public"
value_binding_pattern
let "let"
pattern
simple_identifier "jsName"
= "="
line_string_literal
" "\""
line_str_text "LiquidTabsPlugin"
" "\""
property_declaration (+60 nodes collapsed)
function_declaration
modifiers
visibility_modifier
public "public"
member_modifier
override "override"
func "func"
simple_identifier "load"
( "("
) ")"
function_body
{ "{"
statements
call_expression
navigation_expression
super_expression
super "super"
navigation_suffix
. "."
simple_identifier "load"
call_suffix
value_arguments
( "("
) ")"
assignment
directly_assignable_expression
navigation_expression
simple_identifier "LiquidTabsPlugin"
navigation_suffix
. "."
simple_identifier "shared"
= "="
self_expression
self "self"
} "}"
comment "// MARK: - Methods from JS"
comment "/// Configure tabs from JS."
comment "/// Expected args:"
comment "/// { tabs: [{ id, title, systemImage, role }] }"
function_declaration (+351 nodes collapsed)
comment "/// Programmatically select a tab by id."
comment "/// { id: string }"
function_declaration (+102 nodes collapsed)
comment "// MARK: - Events to JS"
function_declaration (+39 nodes collapsed)
function_declaration (+39 nodes collapsed)
} "}"

After

source_file
import_declaration
import "import"
identifier
simple_identifier "Foundation"
import_declaration
import "import"
identifier
simple_identifier "Capacitor"
import_declaration
import "import"
identifier
simple_identifier "SwiftUI"
import_declaration
import "import"
identifier
simple_identifier "WebKit"
class_declaration
modifiers
attribute
@ "@"
user_type
type_identifier "objc"
( "("
simple_identifier "LiquidTabsPlugin"
) ")"
visibility_modifier
public "public"
class "class"
type_identifier "LiquidTabsPlugin"
: ":"
inheritance_specifier
user_type
type_identifier "CAPPlugin"
, ","
inheritance_specifier
user_type
type_identifier "CAPBridgedPlugin"
class_body
{ "{"
comment "// So SwiftUI can notify JS"
property_declaration
modifiers
property_modifier
static "static"
ownership_modifier
weak "weak"
value_binding_pattern
var "var"
pattern
simple_identifier "shared"
type_annotation
: ":"
optional_type
user_type
type_identifier "LiquidTabsPlugin"
?
? "?"
property_declaration
modifiers
visibility_modifier
private "private"
value_binding_pattern
let "let"
pattern
simple_identifier "store"
= "="
navigation_expression
simple_identifier "LiquidTabsStore"
navigation_suffix
. "."
simple_identifier "shared"
property_declaration
modifiers
visibility_modifier
private "private"
value_binding_pattern
var "var"
pattern
simple_identifier "keyboardHackScriptInstalled"
= "="
boolean_literal
false "false"
property_declaration
modifiers
visibility_modifier
private "private"
value_binding_pattern
let "let"
pattern
simple_identifier "keyboardHackHandlerName"
= "="
line_string_literal
" "\""
line_str_text "keyboardHackKey"
" "\""
property_declaration
modifiers
visibility_modifier
public "public"
value_binding_pattern
let "let"
pattern
simple_identifier "identifier"
= "="
line_string_literal
" "\""
line_str_text "LiquidTabsPlugin"
" "\""
property_declaration
modifiers
visibility_modifier
public "public"
value_binding_pattern
let "let"
pattern
simple_identifier "jsName"
= "="
line_string_literal
" "\""
line_str_text "LiquidTabsPlugin"
" "\""
property_declaration (+60 nodes collapsed)
function_declaration
modifiers
visibility_modifier
public "public"
member_modifier
override "override"
func "func"
simple_identifier "load"
( "("
) ")"
function_body
{ "{"
statements
call_expression
navigation_expression
super_expression
super "super"
navigation_suffix
. "."
simple_identifier "load"
call_suffix
value_arguments
( "("
) ")"
assignment
directly_assignable_expression
navigation_expression
simple_identifier "LiquidTabsPlugin"
navigation_suffix
. "."
simple_identifier "shared"
= "="
self_expression
self "self"
call_expression
simple_identifier "installKeyboardHackScript"
call_suffix
value_arguments
( "("
) ")"
} "}"
comment "// MARK: - Methods from JS"
comment "/// Configure tabs from JS."
comment "/// Expected args:"
comment "/// { tabs: [{ id, title, systemImage, role }] }"
function_declaration (+351 nodes collapsed)
comment "/// Programmatically select a tab by id."
comment "/// { id: string }"
function_declaration (+102 nodes collapsed)
comment "// MARK: - Events to JS"
function_declaration (+39 nodes collapsed)
function_declaration (+39 nodes collapsed)
function_declaration
func "func"
simple_identifier "notifyKeyboardHackKey"
( "("
parameter
simple_identifier "key"
: ":"
user_type
type_identifier "String"
) ")"
function_body
{ "{"
statements
call_expression
simple_identifier "notifyListeners"
call_suffix
value_arguments
( "("
value_argument
line_string_literal
" "\""
line_str_text "keyboardHackKey"
" "\""
, ","
value_argument
value_argument_label
simple_identifier "data"
: ":"
dictionary_literal
[ "["
line_string_literal
" "\""
line_str_text "key"
" "\""
: ":"
simple_identifier "key"
] "]"
) ")"
} "}"
function_declaration
modifiers
visibility_modifier
private "private"
func "func"
simple_identifier "installKeyboardHackScript"
( "("
) ")"
function_body
{ "{"
statements
guard_statement
guard "guard"
prefix_expression
bang "!"
simple_identifier "keyboardHackScriptInstalled"
, ","
value_binding_pattern
let "let"
simple_identifier "controller"
= "="
navigation_expression
navigation_expression
navigation_expression
simple_identifier "bridge"
?
? "?"
navigation_suffix
. "."
simple_identifier "webView"
?
? "?"
navigation_suffix
. "."
simple_identifier "configuration"
navigation_suffix
. "."
simple_identifier "userContentController"
else "else"
{ "{"
statements
control_transfer_statement
return "return"
} "}"
assignment
directly_assignable_expression
simple_identifier "keyboardHackScriptInstalled"
= "="
boolean_literal
true "true"
call_expression
navigation_expression
simple_identifier "controller"
navigation_suffix
. "."
simple_identifier "removeScriptMessageHandler"
call_suffix
value_arguments
( "("
value_argument
value_argument_label
simple_identifier "forName"
: ":"
simple_identifier "keyboardHackHandlerName"
) ")"
call_expression
navigation_expression
simple_identifier "controller"
navigation_suffix
. "."
simple_identifier "add"
call_suffix
value_arguments
( "("
value_argument
self_expression
self "self"
, ","
value_argument
value_argument_label
simple_identifier "name"
: ":"
simple_identifier "keyboardHackHandlerName"
) ")"
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "source"
= "="
multi_line_string_literal
""" "\"\"\""
multi_line_str_text "\n (function() {\n if (window.__logseqKeyboard"...
\( "\\("
interpolated_expression
simple_identifier "keyboardHackHandlerName"
) ")"
multi_line_str_text ".postMessage({ key: k });\n } catch (_) {}\n "...
""" "\"\"\""
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "script"
= "="
call_expression
simple_identifier "WKUserScript"
call_suffix
value_arguments
( "("
value_argument
value_argument_label
simple_identifier "source"
: ":"
simple_identifier "source"
, ","
value_argument
value_argument_label
simple_identifier "injectionTime"
: ":"
prefix_expression
. "."
simple_identifier "atDocumentStart"
, ","
value_argument
value_argument_label
simple_identifier "forMainFrameOnly"
: ":"
boolean_literal
false "false"
) ")"
call_expression
navigation_expression
simple_identifier "controller"
navigation_suffix
. "."
simple_identifier "addUserScript"
call_suffix
value_arguments
( "("
value_argument
simple_identifier "script"
) ")"
} "}"
} "}"
class_declaration
extension "extension"
user_type
type_identifier "LiquidTabsPlugin"
: ":"
inheritance_specifier
user_type
type_identifier "WKScriptMessageHandler"
class_body
{ "{"
function_declaration
modifiers
visibility_modifier
public "public"
func "func"
simple_identifier "userContentController"
( "("
parameter
simple_identifier "_"
simple_identifier "userContentController"
: ":"
user_type
type_identifier "WKUserContentController"
, ","
parameter
simple_identifier "didReceive"
simple_identifier "message"
: ":"
user_type
type_identifier "WKScriptMessage"
) ")"
function_body
{ "{"
statements
guard_statement
guard "guard"
equality_expression
navigation_expression
simple_identifier "message"
navigation_suffix
. "."
simple_identifier "name"
== "=="
simple_identifier "keyboardHackHandlerName"
else "else"
{ "{"
statements
control_transfer_statement
return "return"
} "}"
if_statement
if "if"
value_binding_pattern
let "let"
simple_identifier "body"
= "="
as_expression
navigation_expression
simple_identifier "message"
navigation_suffix
. "."
simple_identifier "body"
as_operator
as? "as?"
dictionary_type
[ "["
user_type
type_identifier "String"
: ":"
user_type
type_identifier "Any"
] "]"
, ","
value_binding_pattern
let "let"
simple_identifier "key"
= "="
as_expression
call_expression
simple_identifier "body"
call_suffix
value_arguments
[ "["
value_argument
line_string_literal
" "\""
line_str_text "key"
" "\""
] "]"
as_operator
as? "as?"
user_type
type_identifier "String"
{ "{"
statements
call_expression
simple_identifier "notifyKeyboardHackKey"
call_suffix
value_arguments
( "("
value_argument
value_argument_label
simple_identifier "key"
: ":"
simple_identifier "key"
) ")"
} "}"
} "}"
} "}"