Cocoa: looking for a general strategy for programmatic manipulation of NSTextView storage without messing up undo

前端 未结 2 1660
旧巷少年郎
旧巷少年郎 2020-12-24 08:13

I am writing a special-purpose text editor in cocoa that does things like automatic text substitution, inline text completions (ala Xcode), etc.

I n

2条回答
  •  醉话见心
    2020-12-24 09:05

    Right, this is by no means a perfect solution, but it is a solution of sorts.

    The text storage updates the undo manager based off "groups". These groups cluster together a series of edits (which I can't quite remember of the top of my head), but I do remember that a new one is created when the selection is altered.

    This leads to the possible solution of quickly changing the selection to something else and then reverting it back. Not an ideal solution but it may be enough to force the text storage to push a new state to the undo manager.

    I shall take a bit more of a look and investigation and see if I can't find/trace exactly what happens.

    edit: I should probably mention that it's been a while since I've used NSTextView and don't currently have access to Xcode on this machine to verify that this works still. Hopefully it will.

提交回复
热议问题