CleanCocoa / CleanCocoa/DeclarativeTextKit

Command block that restores scroll offsets and selection like Emac Lisp save-excursion

Abierto
#4 1 comentario 0 reacciones 0 asignados Ver en GitHub
enhancement
Lenguaje dominante
Swift
Estrellas
50
Forks
0
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

> 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:

![example](https://github.com/CleanCocoa/DeclarativeTextKit/assets/59080/3f19b40b-c1dd-49c7-8276-a1ccb6a3c328)
Source and fix:

`UITextView` doesn't have this problem.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Empieza probando si este comportamiento es necesario y, después, inspecciona el comportamiento de Buffer.character(at:) y NSTextStorage.processEditing() descrito en el issue. Compara los casos de NSTextView y UITextView antes de elegir un enfoque de implementación. La tarea estará terminada cuando un comando pueda realizar mutaciones en el búfer y restaurar la selección y el desplazamiento de scroll anteriores cuando se requiera este comportamiento.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
swift
Área
desktop-dev
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.