Skip to content

Commit ae7fd35

Browse files
Merge pull request #272 from stevengharris/tooltipFixes
Add help/tooltips via toolbarconfig to MarkupToolbar
2 parents b16ec20 + 3255b4d commit ae7fd35

9 files changed

Lines changed: 163 additions & 61 deletions

File tree

MarkupEditor/Resources/markup-editor.js

Lines changed: 53 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MarkupEditor/Resources/toolbarconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,29 @@
4848
"header": true,
4949
"border": true
5050
},
51+
"help": {
52+
"style": "Set paragraph style",
53+
"bold": "Toggle bold",
54+
"italic": "Toggle italic",
55+
"underline": "Toggle underline",
56+
"code": "Toggle code",
57+
"strikethrough": "Toggle strikethrough",
58+
"subscript": "Toggle subscript",
59+
"superscript": "Toggle superscript",
60+
"bullet": "Toggle bulleted list",
61+
"number": "Toggle numbered list",
62+
"indent": "Increase indent",
63+
"outdent": "Decrease indent",
64+
"link": "Insert/edit link",
65+
"image": "Insert/edit image",
66+
"table": "Insert/edit table",
67+
"search": "Toggle search",
68+
"searchForward": "Search forward",
69+
"searchBackward": "Search backward",
70+
"matchCase": "Match case",
71+
"undo": "Undo",
72+
"redo": "Redo"
73+
},
5174
"augmentation": {
5275
"prepend": null,
5376
"append": null

MarkupEditor/Toolbars/CorrectionToolbar.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ public struct CorrectionToolbar: View {
2020
ToolbarImageButton(
2121
systemName: "arrow.uturn.backward",
2222
action: { observedWebView.selectedWebView?.undo() },
23+
help: ToolbarContents.shared.helpContents.undo,
2324
onHover: { over in hoverLabel = Text(over ? "Undo" : "Correction") }
2425
)
2526
ToolbarImageButton(
2627
systemName: "arrow.uturn.forward",
2728
action: { observedWebView.selectedWebView?.redo() },
29+
help: ToolbarContents.shared.helpContents.redo,
2830
onHover: { over in hoverLabel = Text(over ? "Redo" : "Correction") }
2931
)
3032
}

MarkupEditor/Toolbars/FormatToolbar.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,29 @@ public struct FormatToolbar: View {
2424
systemName: "bold",
2525
action: { observedWebView.selectedWebView?.bold() },
2626
active: $selectionState.bold,
27-
onHover: { over in hoverLabel = Text(over ? "Bold" : "Text Format") }
27+
help: ToolbarContents.shared.helpContents.bold,
28+
onHover: onHover(over:)
2829
)
2930
ToolbarImageButton (
3031
systemName: "italic",
3132
action: { observedWebView.selectedWebView?.italic() },
3233
active: $selectionState.italic,
34+
help: ToolbarContents.shared.helpContents.italic,
3335
onHover: { over in hoverLabel = Text(over ? "Italic" : "Text Format") }
3436
)
3537
ToolbarImageButton(
3638
systemName: "underline",
3739
action: { observedWebView.selectedWebView?.underline() },
3840
active: $selectionState.underline,
41+
help: ToolbarContents.shared.helpContents.underline,
3942
onHover: { over in hoverLabel = Text(over ? "Underline" : "Text Format") }
4043
)
4144
if contents.code {
4245
ToolbarImageButton(
4346
systemName: "curlybraces",
4447
action: { observedWebView.selectedWebView?.code() },
4548
active: $selectionState.code,
49+
help: ToolbarContents.shared.helpContents.code,
4650
onHover: { over in hoverLabel = Text(over ? "Code" : "Text Format") }
4751
)
4852
}
@@ -51,6 +55,7 @@ public struct FormatToolbar: View {
5155
systemName: "strikethrough",
5256
action: { observedWebView.selectedWebView?.strike() },
5357
active: $selectionState.strike,
58+
help: ToolbarContents.shared.helpContents.strikethrough,
5459
onHover: { over in hoverLabel = Text(over ? "Strikethrough" : "Text Format") }
5560
)
5661
}
@@ -59,17 +64,23 @@ public struct FormatToolbar: View {
5964
systemName: "textformat.subscript",
6065
action: { observedWebView.selectedWebView?.subscriptText() },
6166
active: $selectionState.sub,
67+
help: ToolbarContents.shared.helpContents.subscript,
6268
onHover: { over in hoverLabel = Text(over ? "Subscript" : "Text Format") }
6369
)
6470
ToolbarImageButton(
6571
systemName: "textformat.superscript",
6672
action: { observedWebView.selectedWebView?.superscript() },
6773
active: $selectionState.sup,
74+
help: ToolbarContents.shared.helpContents.superscript,
6875
onHover: { over in hoverLabel = Text(over ? "Superscript" : "Text Format") }
6976
)
7077
}
7178
}
7279
}
80+
81+
func onHover(over: Bool) {
82+
hoverLabel = Text(over ? "Bold" : "Text Format")
83+
}
7384
}
7485

7586
struct FormatToolbar_Previews: PreviewProvider {

MarkupEditor/Toolbars/InsertToolbar.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public struct InsertToolbar: View {
3535
systemName: "link",
3636
action: { MarkupEditor.selectedWebView?.showPluggableLinkPopover() },
3737
active: Binding<Bool>(get: { selectionState.isInLink }, set: { _ = $0 }),
38+
help: ToolbarContents.shared.helpContents.link,
3839
onHover: { over in if over { hoverLabel = Text("Insert Link") } else { hoverLabel = Text("Insert") } }
3940
)
4041
}
@@ -43,6 +44,7 @@ public struct InsertToolbar: View {
4344
systemName: "photo",
4445
action: { MarkupEditor.selectedWebView?.showPluggableImagePopover() },
4546
active: Binding<Bool>(get: { selectionState.isInImage }, set: { _ = $0 }),
47+
help: ToolbarContents.shared.helpContents.image,
4648
onHover: { over in if over { hoverLabel = Text("Insert Image") } else { hoverLabel = Text("Insert") } }
4749
)
4850
}
@@ -51,6 +53,7 @@ public struct InsertToolbar: View {
5153
systemName: "squareshape.split.3x3",
5254
action: { MarkupEditor.selectedWebView?.showPluggableTablePopover() },
5355
active: Binding<Bool>(get: { selectionState.isInTable }, set: { _ = $0 }),
56+
help: ToolbarContents.shared.helpContents.table,
5457
onHover: { over in if over { hoverLabel = Text(selectionState.isInTable ? "Edit Table" : "Insert Table") } else { hoverLabel = Text("Insert") } }
5558
)
5659
.forcePopover(isPresented: $showTablePopover) {

MarkupEditor/Toolbars/StyleToolbar.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public struct StyleToolbar: View {
4747
Text(selectionState.style.name)
4848
.frame(width: 88, height: toolbarStyle.buttonHeight(), alignment: .center)
4949
}
50+
.help(ToolbarContents.shared.helpContents.style)
5051
.buttonStyle(.borderless)
5152
.menuStyle(.button) // Not available until iOS 16
5253
.frame(width: 88, height: toolbarStyle.buttonHeight())
@@ -70,6 +71,7 @@ public struct StyleToolbar: View {
7071
Text(selectionState.style.name)
7172
.frame(width: 88, height: toolbarStyle.buttonHeight(), alignment: .center)
7273
}
74+
.help(ToolbarContents.shared.helpContents.style)
7375
.menuStyle(.borderlessButton) // Deprecated as of iOS14
7476
.frame(width: 88, height: toolbarStyle.buttonHeight())
7577
.overlay(
@@ -93,13 +95,15 @@ public struct StyleToolbar: View {
9395
systemName: "list.bullet",
9496
action: { observedWebView.selectedWebView?.toggleListItem(type: .UL) },
9597
active: Binding<Bool>(get: { selectionState.isInListItem && selectionState.list == .UL }, set: { _ = $0 }),
98+
help: ToolbarContents.shared.helpContents.bullet,
9699
onHover: { over in hoverLabel = Text(over ? "Bullets" : "Paragraph Style") }
97100
)
98101
case .number:
99102
ToolbarImageButton(
100103
systemName: "list.number",
101104
action: { observedWebView.selectedWebView?.toggleListItem(type: .OL) },
102105
active: Binding<Bool>(get: { selectionState.isInListItem && selectionState.list == .OL }, set: { _ = $0 }),
106+
help: ToolbarContents.shared.helpContents.number,
103107
onHover: { over in hoverLabel = Text(over ? "Numbers" : "Paragraph Style") }
104108
)
105109
}
@@ -110,12 +114,14 @@ public struct StyleToolbar: View {
110114
systemName: "increase.indent",
111115
action: { observedWebView.selectedWebView?.indent() },
112116
active: Binding<Bool>(get: { selectionState.quote }, set: { _ = $0 }),
117+
help: ToolbarContents.shared.helpContents.indent,
113118
onHover: { over in hoverLabel = Text(over ? "Indent" : "Paragraph Style") }
114119
)
115120
ToolbarImageButton(
116121
systemName: "decrease.indent",
117122
action: { observedWebView.selectedWebView?.outdent() },
118123
active: Binding<Bool>(get: { selectionState.quote }, set: { _ = $0 }),
124+
help: ToolbarContents.shared.helpContents.outdent,
119125
onHover: { over in hoverLabel = Text(over ? "Outdent" : "Paragraph Style") }
120126
)
121127
}

MarkupEditor/Utilities/Config/ToolbarConfig.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public struct ToolbarConfig: JSONConfigurable {
2121
public var styleMenu: [String: String?]
2222
public var styleBar: [String: Bool]
2323
public var tableMenu: [String: Bool]
24+
public var help: [String : String]
2425
public var augmentation: [String: Bool?]
2526
public var icons: [String: String]
2627

@@ -65,6 +66,7 @@ public struct ToolbarConfig: JSONConfigurable {
6566
styleMenu: [:],
6667
styleBar: [:],
6768
tableMenu: [:],
69+
help: [:],
6870
augmentation: [:],
6971
icons: [:]
7072
)

0 commit comments

Comments
 (0)