Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some Protyle methods to the plugin API #21

Closed
iamqiz opened this issue Nov 26, 2023 · 5 comments
Closed

Add some Protyle methods to the plugin API #21

iamqiz opened this issue Nov 26, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@iamqiz
Copy link
Contributor

iamqiz commented Nov 26, 2023

----问题1
背景:
想使用plugin.addCommand添加命令,按下快捷键后对光标所在块进行处理,我使用了editorCallback,想知道在其中如何获取当前光标所在块元素

--- 问题2
建议把源码里面 getEditorRange hasClosestBlock hasClosestByAttribute 等函数也开放给插件使用, 避免造轮子

@Vanessa219
Copy link
Member

通过问题2的 API hasClosestBlock 就可以解决问题1了。需要的话我先把 hasClosestBlock 开放出去。由于 getEditorRange 会根据使用场景进行判断,如果光标不在 editor 中会将其设置到第一个块中,从而改变光标的原有位置,就先不放出去了。

@iamqiz
Copy link
Contributor Author

iamqiz commented Nov 28, 2023

@Vanessa219
问题1 解决了(用的Zuoqiu-Yingyi的代码),然后我想实现把段落块转换为列表块,之前在思源源码里调用 turnsIntoOneTransaction 加 type:Blocks2ULs ,很方便,但没开放给插件用,建议开放 , 再加上个 focusBlock .
话说能不能让插件无缝对接思源源码,即能够直接使用思源源码里任意函数而不需要特意开放?

@Vanessa219
Copy link
Member

我抽空整理一下吧。为了安全性思源源码目前不能直接使用,有需求提就好了,我们会尽快完善的。

@Vanessa219
Copy link
Member

  • turnIntoOneTransaction
  • turnIntoTransaction
  • updateTransaction
  • updateBatchTransaction
  • getRange
  • hasClosestBlock
  • focusBlock

@Vanessa219 Vanessa219 self-assigned this Nov 28, 2023
@Vanessa219 Vanessa219 added the enhancement New feature or request label Nov 28, 2023
@Vanessa219 Vanessa219 changed the title [求助] 在editorCallback中如何获取当前光标所在块元素 Add some Protyle methods to the plugin API Nov 28, 2023
@Vanessa219 Vanessa219 changed the title Add some Protyle methods to the plugin API Add some Protyle methods to the plugin API Nov 28, 2023
@iamqiz
Copy link
Contributor Author

iamqiz commented Nov 28, 2023

@Vanessa219 nice~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants