royxue / obsidian-things3-sync

A Obsidian Plugin For Things3 Sync
GNU General Public License v3.0
81 stars 10 forks source link

Todos from multiple line selection? #16

Closed brokosz closed 6 months ago

brokosz commented 1 year ago

Would it be possible to change the plugin behavior to iterate through all lines selected and create a todo for each? Right now, when I select multiple lines and invoke the plugin to Obsidian Things3 Sync: Create Things Todo, only the first one is linked to a Things todo.

- [one](things:///show?id=<TODO_ID_HERE>)
- two
- three

Thanks!!!

royxue commented 1 year ago

@brokosz Sorry for the late reply. I was busy recently, this feature may need some time to finish. Or if you have some free time, it's always welcome to submit a pull request.

royxue commented 8 months ago

@brokosz Hey, Sorry for disturbing. I am going to make a new release of this plugin, just wanna check whether if you are interested submit a PR of this issue. If you are interested, please let me know, and I will include this feature within new version.

brokosz commented 8 months ago

@royxue I'll try, but I'm getting a bunch of compilation error and I'm not really a typescript person. Here's the function I was playing with in main.ts:

function contructTodo(lines: string[], settings: PluginSettings, fileName: string){

  lines.forEach(line => {
    line = line.trim();

    const tags = extractTags(line, settings.defaultTags);

    // Extract other fields like date, title etc from individual line

    const todo = createTodo({
      content: line, 
      tags: tags,
      // other fields
    });

  });

}

// Modify extraction to return array of lines
function extractTitle(text: string): string[] {

  const lines = text.split('\n');

  return lines;

}

// Call with array
const lines = extractTitle(getCurrentLine(editor, view));

constructTodo(lines, settings, fileName);
royxue commented 8 months ago

@brokosz I think it would be better to give with some regex check, if the user selected area has '\n' which means it's including multiple lines, and then it can run with your func.

Yes, TS is annoying, better to deal it with chatgpt it would be easier