refactor(editor): extract pure apply_pending_edits dispatcher (R1) - #156
Merged
Conversation
…bEditar._run Move the edit-application loop (redact / text / image / signature / highlight / note / draw / delete_annot / text_edit branches, plus the post-loop subset_fonts) out of TabEditar._run into a new pure module app/editor/apply_edits.py. apply_pending_edits(doc, pending, *, warn_fn) takes an already-open (and authenticated) fitz.Document, mutates it in place and does no file I/O and no Qt work, so it is unit-testable headless. It returns an ApplyResult carrying the text_fit_warnings and the embedded_font flag. TabEditar._run keeps only UI orchestration: opening the document, password/encryption prompts, the non-latin heads-up, the defensive try/except, the atomic tempfile+os.replace write, encrypted/plain save, reload and the toast/QMessageBox dialogs. Behaviour is identical; the order of operations (apply edits -> subset_fonts -> atomic write -> save -> reload) is unchanged. Add tests/test_apply_edits.py exercising the dispatcher without a GUI (text_edit, redact, text, draw, note, delete_annot, the _existing gate and the warn_fn / ApplyResult warning propagation). Update the three source-scraping regression tests that pinned the moved loop to tab.py so they read the new apply_edits.py module. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add direct headless tests for the two previously-uncovered branches of apply_pending_edits: * image/signature: parametrised over both type strings (they share one branch); writes a real PNG via fitz.Pixmap, applies the edit and asserts exactly one raster is embedded after a bytes round-trip. * highlight: asserts a single Highlight annotation is added over the text rect and stamped with the requested stroke colour. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Wrap the source-inspection open().read() calls in context managers so the file handle is always closed. Fixes CodeQL alert #303 (File is not always closed) at tests/test_pdfapps.py and the same pattern in nine sibling audit-regression tests. No test logic or assertions changed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Deploying pdfapps with
|
| Latest commit: |
a1678e8
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ca054e52.pdfapps.pages.dev |
| Branch Preview URL: | https://refactor-editor-apply-edits.pdfapps.pages.dev |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sumario
Refactor puro (R1 do plano de modularidade do editor). Sem alteracao de comportamento.
O que muda
Extrai o corpo do loop
for e in self._pendingdeTabEditar._run(app/editor/tab.py) para uma funcao pura emapp/editor/apply_edits.py:redact,text,image,signature,highlight,note,draw,delete_annot,text_edit.TabEditar._runpassa a ser so orquestracao de UI: open/password/encriptacao, escrita atomica, save, reload e dialogos. Osubset_fontscontinua a ser chamado no mesmo momento e sob o mesmo gate.Beneficio
Melhora a testabilidade: a logica de dominio (aplicacao de edicoes ao documento) fica testavel sem GUI.
Testes
image/highlight.Notas
main).