Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐞 Missing Function for Replacing Characters with Multiple Ranges and Strings #44

Closed
tom-ludwig opened this issue Aug 20, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@tom-ludwig
Copy link
Member

tom-ludwig commented Aug 20, 2024

Description

The current implementation lacks a function that accepts multiple ranges and corresponding strings for replacement. We need a method similar to the following:

public func replaceCharacters(in ranges: [[NSRange]], with strings: [String])

This function should allow replacing characters in multiple ranges with their respective strings.
While you can call replaceCharacters(_:with:) multiple times, each call is treated as a separate insertion, which creates a misleading undo history.

Example:

Comments:

Screen.Recording.2024-08-20.at.7.13.48.PM.mov

To Reproduce

x

Expected Behavior

x

Version Information

No response

Additional Context

No response

Screenshots

No response

@tom-ludwig tom-ludwig added the bug Something isn't working label Aug 20, 2024
@tom-ludwig tom-ludwig self-assigned this Aug 20, 2024
@thecoolwinter
Copy link
Contributor

thecoolwinter commented Aug 22, 2024

After starting working on this, I don't think it's a necessary API. If the issue it's solving is undo grouping, you should be able to call textView.undoManager?.beginGrouping() before and textView.undoManager?.endGrouping() after applying all your edits to force the undo manager to group them all into one undo group.

An API call like this would have some requirements that would be hard to indicate through a simple method call. Like requiring all the ranges to be non-overlapping, and requiring that range groups are ordered so that edits can be applied to the text without modifying the given ranges and strings. I think that should be handled by the library consumer.

@thecoolwinter thecoolwinter moved this from 🆕 New to 🏃‍♂️ In Progress in CodeEdit Project Aug 22, 2024
@tom-ludwig
Copy link
Member Author

You’re absolutely right; it makes more sense to implement that situation specifically

@tom-ludwig tom-ludwig closed this as not planned Won't fix, can't repro, duplicate, stale Aug 26, 2024
@github-project-automation github-project-automation bot moved this from 🏃‍♂️ In Progress to 🏁 Complete in CodeEdit Project Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 🏁 Complete
Development

No branches or pull requests

2 participants