像 Finder 一样在 NSOutlineView 中编辑文本

Edit text in NSOutlineView like Finder

如果您在 Finder 中重命名文件,文本字段会水平扩展至大约列的宽度。然后它在滚动之前垂直扩展到三行。我假设这必须在大纲视图外的文本字段中完成。我可以在输入时调整文本字段的大小。我只是不知道如何在必要时将它放在大纲视图上。如果大纲视图滚动,请将其固定在行中。有没有人有任何见解?谢谢!

文本编辑由专门的 NSText 处理,称为“字段编辑器”。此共享单一视图用于 window 中发生的所有文本编辑。它与通常显示文本的内容(不编辑时)分开。

文档如下: https://developer.apple.com/documentation/appkit/nswindow/1419647-fieldeditor

如文档讨论部分所述,您可以使用和自定义另一个字段编辑器。这应该是您任务的起点。

The window’s delegate can substitute a custom field editor in place of the window’s field editor by implementing windowWillReturnFieldEditor(_:to:). The custom field editor can become the default editor (common to all text-displaying objects) or specific to a particular text-displaying object (object).

NSControl 文档中还有一个关于字段编辑器的部分可能会有所帮助。