Oni: Snippets and textwidth issue

Created on 4 Sep 2018  路  4Comments  路  Source: onivim/oni

Oni Version: master
Operating System: Windows 10 Pro 64 Bit

Issue: When using a snippet along with a textwidth set, the snippet seems to break if the usage of a snippet pushes the text over the textwidth.

Expected behavior: Text to wrap and cause no issues.

Actual behavior: Text that wraps to the next line is repeatedly infintely.

Steps to reproduce:

Add a snippet (globally or for a given file type, here I do a markdown one), like this:

    "URL": {
        "prefix": "url",
        "body": ["[${1:description}](${2:url})"],
        "description": "A markdown URL link."
    },

Open a file with a snippet defined and set the textwidth to some value (I'm using 88, set textwidth=88)
Write some text close to the text width, but not quite, say 85 chars:

This is a line that is going to be pretty close to my text width but not quite over.

Swap some earlier text to a snippet, ie swap 'line' to a URL using the snippet.
The snippet is inserted fine:

This is a [description](url) that is going to be pretty close to my text width but not quite over.

Then when you edit the snippet variables, the line continues to duplicate itself:

image

bug insider

Most helpful comment

@CrossR,

I looked into this a bit further, and I believe that the problem is rooted in the way placeholders are calculated in SnippetSession.ts. Specifically in _synchronizeUpdatedPlaceholders()_ when calculating the _start_ and _end_ position of the placeholder. The line length is used, but it doesn't take into consideration the content of the line following the snippet.

oni_snippet_length

I believe this causes the text following what you are inserting to be included in the placeholder itself, and ultimately repeated.

All 4 comments

Hi @CrossR,

I was able to replicate this issue with _textwidth_ set to 0. Could the problem not have to do with textwidth, but instead when there is text following the snippet that is being inserted?

oni_issue_2550

FYI, this is also on Windows 10 and Oni v3.6.0.

@CrossR,

I looked into this a bit further, and I believe that the problem is rooted in the way placeholders are calculated in SnippetSession.ts. Specifically in _synchronizeUpdatedPlaceholders()_ when calculating the _start_ and _end_ position of the placeholder. The line length is used, but it doesn't take into consideration the content of the line following the snippet.

oni_snippet_length

I believe this causes the text following what you are inserting to be included in the placeholder itself, and ultimately repeated.

Thanks for debugging this @cmpadden !

That makes sense, then because the bounds are off, we are end up calling updateSnippet with the incorrect values which does the actual setting of the lines.

I'll try and take a look into fixing it this week, assuming you haven't already done so!

No problem @CrossR. I haven't come up with a solution yet as I have a very limited experience with these technologies, though I am learning. I'd appreciate you taking a look so I can see how you approach solving the problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

magopian picture magopian  路  3Comments

badosu picture badosu  路  3Comments

akinsho picture akinsho  路  3Comments

IvRRimum picture IvRRimum  路  3Comments

badosu picture badosu  路  3Comments