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 a new API Move block #7903

Closed
frostime opened this issue Apr 6, 2023 · 6 comments
Closed

Add a new API Move block #7903

frostime opened this issue Apr 6, 2023 · 6 comments
Assignees
Milestone

Comments

@frostime
Copy link
Contributor

frostime commented Apr 6, 2023

添加 API 移动块

In what scenarios do you need this feature?

中文

使用背景

无论怎么推崇双链写作法,思源都是一款提供了文档树的笔记软件,为了更好地支持用户对于整理文档组织逻辑的需求,移动 blocks 功能还是有必要的。

例如:我有好几个笔记本,每个笔记本的主题都完全不同。我并不想把所有的记录都写在同一个笔记本下,原因在于:

  1. 有些笔记本具有比较强的场景性,我不想让这些工具性笔记入侵自己的私人笔记——所以我需要区分笔记本
  2. 我喜欢在 Diary 中记录
  3. 我希望笔记本 A 里面所有的内容、双向链接都尽可能在 A 内部 —— 所以每个笔记本我都会使用 Diary 功能。

但是也不想每次记笔记都来回切换笔记本。所以我的做法一般是写的时候全部在统一一个笔记本内,然后等到晚上整理的时候,把各个主题块移动到各自的笔记本下。

功能请求

在 UI 操作中,我们可以通过选择+拖动的方式,把若干的块移动到另一个 parent blocks 下。我希望可以提供类似功能的 API 。

(}{F4~TU(S@I`OZI628LSYK

目前我们可以在 API 里曲折地实现类似的功能:1) 获取 markdown 内容 2)用 insertBlock 插入新的地方 3) 删除原来的 block。但是这个方法,在于剪切的方式会丢失原本的 ID,如果需要移动的 blocks 本身有反向链接,那么那个链接的目标就会丢失。

所以我认为需要一个更加原生的、通过修改 parent_id ,在保证不丢失原始的 ID 信息的前提下实现移动块的方法。

English

Background

No matter how much we praise the double-linked writing method, Siyuan is still a note-taking software that provides a document tree. In order to better support users' needs for organizing document logic, the move blocks function is necessary.

For example: I have several notebooks, each with a completely different main topic. I don't want to write all my notes in the same notebook for the following reasons:

  1. Some notebooks highly depends on some specific scenario, and I don't want these tool-oriented notes to invade my personal notes - so I need to distribute them to different notebooks.
  2. I like to record in Diary.
  3. I hope that all content and bi-directional links in Notebook A will be generally within A - so I will use the Diary for each notebook separately.

But I also don’t want to switch notebooks every time I take notes. So my approach is to write everything in the same notebook when writing, and then move each blocks to their correspondent notebooks when organizing today's notes at night.

Feature Request

In UI operation, we can move several blocks to another parent block by selecting and dragging. I hope to provide an API with the same functionality.

Currently, we can implement similar functions in the API in a convoluted way: 1) Get the markdown content 2) Insert a new block with insertBlock 3) Delete the original block. However, this method will lose the original ID in the cutting process. If the blocks that need to be moved have reverse links themselves, then the target of that link will be lost.

Therefore, I think we need a more native method to move blocks by modifying the parent_id while ensuring that the original ID information is not lost.

By the way

感觉同时写中英文的 Issue 好麻烦。。。

Describe the optimal solution

I know little about your source code. But as I think it might no be so hard to implement the aforementioned functionality. Cause it seems that we can make it use by changing the parent_id in database.

Following given the template definition for this API.

  • /api/block/moveBlocks

  • Parameters

    Move all srcBlocksID blocks to desParentID

    {
      "srcBlocksID": ["20220107173950-7f9m1nb", "20211229114650-vrek5x6"],
      "desParentID": "20220107173950-af61gxb",
      "action": "append | prepend"
    }
    • srcBlocksID: List

    • desParentID: str

    • action

      • append: Like /api/block/appendBlock
      • prepend: Like /api/block/prependBlock
  • Return:

    It depends on you.

Describe the candidate solution

No response

Other information

No response

@frostime frostime changed the title Add API: Move blocks | 移动块 [Feature Request] Add New API: Move blocks | 移动块 Apr 6, 2023
@88250 88250 changed the title [Feature Request] Add New API: Move blocks | 移动块 Add a new API Move block Apr 6, 2023
@88250 88250 self-assigned this Apr 6, 2023
@88250 88250 added this to the 2.8.4 milestone Apr 6, 2023
@88250
Copy link
Member

88250 commented Apr 6, 2023

目前只能提供非批量移动接口,如果要批量操作的话需要多次调用。

Issue 的话不用双语,使用母语即可,这样反馈效率更高一些。

@frostime
Copy link
Contributor Author

frostime commented Apr 6, 2023

目前只能提供非批量移动接口,如果要批量操作的话需要多次调用。

Issue 的话不用双语,使用母语即可,这样反馈效率更高一些。

好的,感谢 D大 @88250 。我有些功能细节问题想问一下:移动多个有层级的 block 的过程中要如何保证他们的层级关系?

就比如我下面列举的情况。我有一个标题块 A,下面的是这个文档块的子块 Aa 。显然 A 的 parent 是他所在的文档块,所以移动标题块 A 到另一个文档块下就会更改他的 parent_id。

但是 Aa 的 parnet_id 仍然是 A 没有变,那么后面如果我希望继续保持 Aa 和 A 的层次关系,还有必要移动 Aa吗?

或者更进一步,如果 move api 要实现的话,它的行为逻辑是什么样子的呢?

image

@88250
Copy link
Member

88250 commented Apr 6, 2023

只移动 a 的话 parent_id 会被改成移动后的父块 id,不是 A 的 id。

@frostime
Copy link
Contributor Author

frostime commented Apr 6, 2023

只移动 a 的话 parent_id 会被改成移动后的父块 id,不是 A 的 id。

@88250 也就是说只移动父块会自动破坏原来的父子关系是吗?那么是否意味着,如果需要保持原来的层级关系,就需要:

  1. Move A to new parent X
  2. Get A id
  3. Move Aa to parent A

也就是说,如果需要移动具有层级关系的一堆块,需要手动解析他们的关系,然后在 move 的过程中保持原来的层级关系?

88250 added a commit that referenced this issue Apr 6, 2023
88250 added a commit that referenced this issue Apr 6, 2023
@88250
Copy link
Member

88250 commented Apr 6, 2023

标题块比较特殊,它不是容器块,所以如果要带其下方块一起移动的话需要先将标题块折叠。

@88250
Copy link
Member

88250 commented Apr 6, 2023

我先关闭了,如果还有问题请继续跟帖,谢谢 🙏

@88250 88250 closed this as completed Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants