CleanCocoa / CleanCocoa/DeclarativeTextKit
Command block that restores scroll offsets and selection like Emac Lisp save-excursion
- Langage dominant
- Swift
- Étoiles
- 50
- Forks
- 0
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
> Note: This may not be needed in practice at all. We have to test this.
-------------
One feature that Emacs Lisp provides is to jump around in a buffer and read and write text, then restore the context exactly as it was before so that the user doesn't perceive anything. This is called `save-excursion`.
```swift
// Imagine we're in the middle of a long document here, like
// line 500 of 1000.
SaveExcursion {
Select(LineRange(at: 0)) {
// ... do stuff on the first line ...
}
Select(LineRange(at: buffer.endLocation)) {
// ... do stuff on the last line line ...
}
}
// At this point, we're at line 500 again and the scroll offset is the same as before
```
Unlike our `Buffer.character(at:)`, Emacs buffers can't access substrings without moving them into view. There, the buffer is the model, and moving the reading head also moves the scrolled viewport.
`NSTextView` can show similar behavior when you change characters in one place and attributes in a larger place and the effective range is enlargened; then the `NSTextStorage.processEditing()` run will move the insertion point:

Source and fix:
`UITextView` doesn't have this problem.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par vérifier si ce comportement est nécessaire, puis examinez le comportement de Buffer.character(at:) et NSTextStorage.processEditing() décrit dans l’issue. Comparez les cas NSTextView et UITextView avant de choisir une approche d’implémentation. La tâche sera terminée lorsqu’une commande pourra effectuer des mutations du buffer tout en restaurant la sélection précédente et le décalage de défilement lorsque le comportement est requis.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- swift
- Domaine
- desktop-dev
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100