跳到正文
DEV Community· Ranch Jiao·· 2 小時前AI 評分39

PasteCharm 套用範本後,復原應還原哪些內容?

What should Undo restore after you try a template?

AI 導讀

PasteCharm 在套用範本前保存文字、樣式、分隔線和表情符號設定,以及當時啟用的範本;執行「Undo template」後,會還原這些狀態、更新預覽,並將焦點放回編輯器。範本變更只提供一步復原,套用另一個範本會更新復原點;清除操作則結束當前頁面的待復原狀態。

正文

Type a couple of lines in the PasteCharm Bio Builder, pick Gothic, and turn off Add divider and Add emoji. Then click one of the shortcuts under Start with a template. The preview changes, and so do the words you just typed.

Now click Undo template below the editor. Your words come back. So do Gothic and the two checkboxes you turned off. If the words came back with the template's styling, you'd still have to fix your draft by hand.

Trying a template should be easy to undo

A template in PasteCharm is a sample bio with a visual style. Applying it changes the editor immediately so you can see the whole result and start editing it. A confirmation dialog would ask you to decide whether to replace your draft before you've seen the template in your preview. Undo lets you see it first.

The tricky bit was deciding what counts as a draft here. The text lives in a textarea. The style, divider, and emoji live in separate controls. Together they produce the preview. A snapshot of just the textarea would leave part of the template behind.

Save what the action replaces

Right before applying a template, PasteCharm remembers the current text, style, divider and emoji settings, and which template was active, if any. Undo restores that snapshot, updates the preview, and returns focus to the editor. That last step puts you back where you can keep typing.

This is one step of undo for template changes. If you apply a second template, Undo takes you back to the state just before that second choice. Clear ends the session's pending template undo, and the snapshot lives in memory for the current page.

Check the result the user sees

The regression test starts with a custom bio, a different style, and both decorations off. After applying a template and undoing it, the test checks the text and each control. It also checks the resulting preview and keyboard focus. The text alone could be correct while the preview still looks wrong.

For actions like this, I'd start by listing everything the user will see change. That's a better starting point for Undo than the shape of the form state.

This article was drafted with AI from PasteCharm’s implementation and test cases.

來源:DEV Community · dev.to