Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Sources/CodeEditTextView/Extensions/CharacterSet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// CharacterSet.swift
// CodeEditTextView
//
// Created by Abe Malla on 3/29/25.
//

import Foundation

extension CharacterSet {
/// Returns a character set containing the characters common in code names
static let codeIdentifierCharacters: CharacterSet = .alphanumerics
.union(.init(charactersIn: "_"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ package extension TextSelectionManager {

if hasFoundValidWordChar && CharacterSet.punctuationCharacters
.union(.whitespacesAndNewlines)
.subtracting(CharacterSet.codeIdentifierCharacters)
.isSuperset(of: CharacterSet(charactersIn: substring)) {
stop.pointee = true
return
} else if CharacterSet.alphanumerics.isSuperset(of: CharacterSet(charactersIn: substring)) {
} else if CharacterSet.codeIdentifierCharacters.isSuperset(of: CharacterSet(charactersIn: substring)) {
hasFoundValidWordChar = true
}
rangeToDelete.length += substring.count
Expand Down
4 changes: 2 additions & 2 deletions Sources/CodeEditTextView/TextView/TextView+Select.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ extension TextView {
}
let charSet = CharacterSet(charactersIn: String(char))
let characterSet: CharacterSet
if CharacterSet.alphanumerics.isSuperset(of: charSet) {
characterSet = .alphanumerics
if CharacterSet.codeIdentifierCharacters.isSuperset(of: charSet) {
characterSet = .codeIdentifierCharacters
} else if CharacterSet.whitespaces.isSuperset(of: charSet) {
characterSet = .whitespaces
} else if CharacterSet.newlines.isSuperset(of: charSet) {
Expand Down