Skip to content

Commit 3377280

Browse files
revolterhebertialmeida
authored andcommitted
Fixed code style (FolioReader#191)
Extracted duplicate "hack" into a clearly named function. Previously, not all instances had the explanation comment, and its side effect was not clear.
1 parent 4d1366a commit 3377280

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

Source/FolioReaderWebView.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ open class FolioReaderWebView: UIWebView {
5050
} else {
5151
if let textToShare = self.js("getSelectedText()") {
5252
FolioReader.shared.readerCenter?.presentQuoteShare(textToShare)
53-
self.isUserInteractionEnabled = false
54-
self.isUserInteractionEnabled = true
53+
54+
self.clearTextSelection()
5555
}
5656
}
5757
self.setMenuVisible(false)
@@ -108,9 +108,7 @@ open class FolioReaderWebView: UIWebView {
108108
let startOffset = dic["startOffset"]!
109109
let endOffset = dic["endOffset"]!
110110

111-
// Force remove text selection
112-
isUserInteractionEnabled = false
113-
isUserInteractionEnabled = true
111+
self.clearTextSelection()
114112

115113
createMenu(options: true)
116114
setMenuVisible(true, andRect: rect)
@@ -129,8 +127,8 @@ open class FolioReaderWebView: UIWebView {
129127
let selectedText = js("getSelectedText()")
130128

131129
setMenuVisible(false)
132-
isUserInteractionEnabled = false
133-
isUserInteractionEnabled = true
130+
131+
self.clearTextSelection()
134132

135133
let vc = UIReferenceLibraryViewController(term: selectedText! )
136134
vc.view.tintColor = readerConfig.tintColor
@@ -140,10 +138,7 @@ open class FolioReaderWebView: UIWebView {
140138
func play(_ sender: UIMenuController?) {
141139
FolioReader.shared.readerAudioPlayer?.play()
142140

143-
// Force remove text selection
144-
// @NOTE: this doesn't seem to always work
145-
isUserInteractionEnabled = false
146-
isUserInteractionEnabled = true
141+
self.clearTextSelection()
147142
}
148143

149144
func setYellow(_ sender: UIMenuController?) {
@@ -273,7 +268,15 @@ open class FolioReaderWebView: UIWebView {
273268
return callback
274269
}
275270

276-
// MARK: WebView direction config
271+
// MARK: WebView
272+
273+
func clearTextSelection() {
274+
// Forces text selection clearing
275+
// @NOTE: this doesn't seem to always work
276+
277+
self.isUserInteractionEnabled = false
278+
self.isUserInteractionEnabled = true
279+
}
277280

278281
func setupScrollDirection() {
279282
switch readerConfig.scrollDirection {

0 commit comments

Comments
 (0)