Skip to content

Conversation

cherifGsoul
Copy link
Contributor

@cherifGsoul cherifGsoul commented Jul 5, 2019

This is needed by canjs/bit-docs-html-canjs#556

This prevent collapsing one line of code, for example the following will not collapse line 1 and 8:

// Creates a mock backend with 3 todos
import { todoFixture } from "//unpkg.com/can-demo-models@5";
todoFixture(3);

import { Component } from "//unpkg.com/can@5/core.mjs";

Component.extend({
	tag: "todos-app",
	view: `
		<h1>Today’s to-dos</h1>
	`,
	ViewModel: {
	}
});
<span line-highlight='2-7,9-14,only'/>

Fixes canjs/bit-docs-html-canjs#556

@cherifGsoul cherifGsoul changed the title Don't collapse one of code Don't collapse one line of code Jul 5, 2019
@cherifGsoul cherifGsoul requested a review from chasenlehara July 5, 2019 16:25
if (range[0] > current + padding) {
collapse.push(current + '-' + (range[0] - 1 - padding));
var collapseEnd = (range[0] - 1 - padding);
if (collapseEnd !== current) {
Copy link
Member

Choose a reason for hiding this comment

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

@cherifGsoul can you explain this logic change? Would this show the lines between a set of highlights like:

@highlight 1-3,33-55

range[0] > current + padding would be true when range[0] is 33

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@justinbmeyer The logic is to compare the first line and the last line of collapsible:

  • Using current which is initialized to 1 or calculated in this expression at the end of the loop current = (range[1] || range[0]) + padding + 1
  • In each iteration of the loop collapseEnd is calculated based on the first item range[0] of the new range of line highlight collapseEnd = (range[0] - 1 - padding)

In short:
current = currentRange[1] + 1 + padding
next = nextRange[0] - 1 - padding

next - current should be greater than 1 to make a collapsible

So for @highlight 1-3,33-55 we have a collapsible between [7, 29] and it shows only the 3 lines for padding between highlights:
current = 3 + 1 + 3 // => start collapsible from line 7
next = 33 - 1 - 3 // => close collapsing at the line 29

@cherifGsoul cherifGsoul merged commit b8e76fd into master Jul 8, 2019
@cherifGsoul cherifGsoul deleted the dont-expand-one-line branch July 8, 2019 17:03
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.

Don’t show the expand button for one line of code
2 participants