-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(comments): Add Support for Commenting Multiple Lines (#261)
<!--- IMPORTANT: If this PR addresses multiple unrelated issues, it will be closed until separated. --> ### Description This PR lets you highlight multiple lines and comment them all out at once. ### Related Issues * closes #253 <!--- REQUIRED: Tag all related issues (e.g. * #123) --> <!--- If this PR resolves the issue please specify (e.g. * closes #123) --> <!--- If this PR addresses multiple issues, these issues must be related to one other --> ### Checklist <!--- Add things that are not yet implemented above --> - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots https://github.com/user-attachments/assets/97ae52d5-0fb0-4b25-90e6-2bbc18769856 <!--- REQUIRED: if issue is UI related --> <!--- IMPORTANT: Fill out all required fields. Otherwise we might close this PR temporarily -->
- Loading branch information
1 parent
4e014f7
commit 515b025
Showing
4 changed files
with
244 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Sources/CodeEditSourceEditor/Controller/TextViewController+ToggleCommentCache.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Tommy Ludwig on 23.08.24. | ||
// | ||
|
||
import CodeEditTextView | ||
|
||
extension TextViewController { | ||
/// A cache used to store and manage comment-related information for lines in a text view. | ||
/// This class helps in efficiently inserting or removing comment characters at specific line positions. | ||
struct CommentCache: ~Copyable { | ||
/// Holds necessary information like the lines range | ||
var lineInfos: [TextLineStorage<TextLine>.TextLinePosition?] = [] | ||
/// Caches the content of lines by their indices. Populated only if comment characters need to be inserted. | ||
var lineStrings: [Int: String] = [:] | ||
/// Caches the shift range factors for lines based on their indices. | ||
var shiftRangeFactors: [Int: Int] = [:] | ||
/// Insertion is necessary only if at least one of the selected | ||
/// lines does not already start with `startCommentChars`. | ||
var shouldInsertCommentChars: Bool = false | ||
var startCommentChars: String? | ||
/// The characters used to end a comment. | ||
/// This is applicable for languages (e.g., HTML) | ||
/// that require a closing comment sequence at the end of the line. | ||
var endCommentChars: String? | ||
} | ||
} |