Skip to content

Commit ab9aadc

Browse files
committed
Fix handling for isEditable and isSelectable states
This patch fixes how isEditable and isSelectable properties interact, ensuring proper behavior when either property changes state. The implementation now correctly sets interaction modes based on both properties, adding support for the non-interactive state when neither selection nor editing is enabled. fixes #81
1 parent bac7e3a commit ab9aadc

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

Sources/STTextViewUIKit/STTextView.swift

+14-8
Original file line numberDiff line numberDiff line change
@@ -288,24 +288,23 @@ import STTextViewCommon
288288
// @Invalidating(.insertionPoint, .cursorRects)
289289
@objc dynamic open var isEditable: Bool {
290290
didSet {
291-
isSelectable = isEditable
292-
293-
if !isEditable, isEditable != oldValue {
294-
_ = resignFirstResponder()
291+
if isEditable != oldValue && !isEditable {
292+
resignFirstResponder()
295293
updateEditableInteraction()
296294
}
297-
298295
}
299296
}
300297

301298
/// A Boolean value that controls whether the text views allows the user to select text.
302299
// @Invalidating(.insertionPoint, .cursorRects)
303300
@objc dynamic open var isSelectable: Bool {
304301
didSet {
305-
if !isSelectable {
306-
isEditable = false
302+
if isSelectable != oldValue, !isSelectable {
303+
resignFirstResponder()
304+
updateEditableInteraction()
307305
}
308306
}
307+
309308
}
310309

311310
/// The receiver’s default paragraph style.
@@ -611,10 +610,17 @@ import STTextViewCommon
611610
}
612611
}
613612

613+
func setupNoInteraction() {
614+
removeInteraction(editableTextInteraction)
615+
removeInteraction(nonEditableTextInteraction)
616+
}
617+
614618
if isEditable {
615619
setupEditableInteraction()
616-
} else {
620+
} else if isSelectable {
617621
setupNonEditableInteraction()
622+
} else {
623+
setupNoInteraction()
618624
}
619625
}
620626

0 commit comments

Comments
 (0)