Skip to content

support search and jump - #1

Merged
fxha merged 1 commit into
fxha:ripgrepfrom
Jocs:ripgrep
Jun 12, 2019
Merged

fxha merged 1 commit into
fxha:ripgrepfrom
Jocs:ripgrep

Conversation

@Jocs

@Jocs Jocs commented Jun 10, 2019 •

Copy link
Copy Markdown

Support jump to cursor position by click search result in side bar.


This change is Reviewable

@Jocs

Jocs commented Jun 10, 2019 •

Copy link
Copy Markdown
Author

@fxha There still some bugs, for example, if we search ```javascript, we click the search result, but it will break the render content of the search result file. Maybe I'll handle it after your PR merged or before.

const nextLine = cm.getLine(cursor.line + 1)
cursor = adjustCursor(cursor, preLine, line, nextLine)
return { cursor, markdown }
const adjCursor = cursor => {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, as I comment in this PR, we need to adjustCursor the cursor which get from the search results. Because we can not always find a correct position in preview mode according by the search results.

So, Can we get the previous line and next line of search result line?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not a problem and when searching e.g. for a code block we can safely jump into the next line or code block content. I think it's not a big problem and sufficient to correct find raw text matches but the given cursor from ripgrep may be also invalid due files changes.

Did you tested search of an image link/test?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you tested search of an image link/test?

No, ripgrep can search in the image link, but preview mode didn't support search in the image link any more, maybe we can just scroll to the image, and select the image, when click the search result.

@Jocs Jocs Jun 11, 2019 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found another issue, ripgrep search on the disk, but Mark Text maybe not save the markdown content immediately to the disk. So the click search result the cursor maybe not found in the already not saved tab.(You already mentioned bellow)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can just scroll to the image, and select the image, when click the search result.

That's actually a good idea/improvement.

I found another issue, ripgrep search on the disk, but Mark Text maybe not save the markdown content immediately to the disk. So the click search result the cursor maybe not found in the already not saved tab

Please see below.

@fxha fxha left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vue.esm.js?a026:1897 TypeError: Cannot read property 'substring' of undefined
    at ContentState.addCursorToMarkdown (importMarkdown.js?4b04:428)
    at Muya.setMarkdown (index.js?64a7:147)
    at VueComponent.eval (editor.vue?7b20:654)
    at Array.eval (vue.esm.js?a026:1989)
    at flushCallbacks (vue.esm.js?a026:1915)

when you remove a few lines from the opened tab and click on a search result that match line > current tab lines or the file length on disk is less than the match line.

E.g. Search for foo and the result is in line 3. Click on the result and the file is opened and selected on line 3. Now remove all content except line 1 and click again on the search result line 3.

@Jocs

Jocs commented Jun 11, 2019 •

Copy link
Copy Markdown
Author

when you remove a few lines from the opened tab and click on a search result that match line > current tab lines or the file length on disk is less than the match line.

  1. First, we need to set autoSave's default value to true now?
  2. We need to research after user edit and save any file.
  3. If a matched search result existed on disk but it not existed on the opened tabs? What should we do?

@fxha

fxha commented Jun 11, 2019

Copy link
Copy Markdown
Owner

First, we need to set autoSave's default value to true now?

I would consider autoSave as experimental feature with regard to automatically formating and not supported markdown elements. So keep it disabled by default.

Regarding changed tabs and find in files: I think the easiest fix would be to correct invalid parameters in muya. E.g. when we try to open line 4 but the file on disk/opened tab only has 2 lines then line 2 should be selected and also the same for an invalid offset, select the best offset or position 0.

@Jocs

Jocs commented Jun 12, 2019

Copy link
Copy Markdown
Author

Otherwise, this PR is merged first, then I submit an issue in marktext/marktext, and I am trying to fix the problem that the cursor may not find.

@fxha
fxha merged commit 713e750 into fxha:ripgrep Jun 12, 2019
@Jocs
Jocs deleted the ripgrep branch June 12, 2019 11:53
fxha pushed a commit that referenced this pull request Jun 12, 2019
fxha pushed a commit that referenced this pull request Jun 15, 2019
fxha added a commit that referenced this pull request Jul 3, 2019
* Add ripgrep as find in files backend

* Fix API limit on Appveyor

* Fix css style

* support search and jump (#1)

* Style fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants