Selecting buffers


#1

I am trying to select buffers and I am facing a number of problems.

  1. I want to append certain text and then get it’s buffer. However when I use the following code I get the buffer range from the point where I append the text upto the end of editor window. How do I restrict the buffer to only include the text?
buffer = editor.buffer;
range  = buffer.append("string");
  1. I want to clear all the text in a file using buffer API Link. How do I select the starting point and ending point of the entire text file?

#2

What’s the difference? If you are adding a block of text to the end of the file, then the new end of the file will be at the end of the block of text you’ve just added. Please give us an actual example (with screenshots and code files and stuff) where you expect one outcome and get something different, so that everyone can best understand what’s happening and what needs to happen.

I want to clear all the text in a file using buffer API Link.

What’s wrong with just using buffer.setText("")?

How do I select the starting point and ending point of the entire text file?

The simplest way would be to use editor.selectAll() and then get the Range for that selection.


#3
buffer = editor.buffer;
range  = buffer.append(part.value);

I am trying to highlight some text using two functions.

if(part.added===true){
 marker = editor.markBufferRange(range, {invalidate: 'never'});
 editor.decorateMarker(marker, {type: 'highlight', class: 'addedText'});
 this.markers.push(marker);
}
else if(part.removed===true){
 marker = editor.markBufferRange(range, {invalidate: 'never'});
 editor.decorateMarker(marker, {type: 'highlight', class: 'removedText'});
 this.markers.push(marker);
}

Otherwise I am simply appending the text.
I am also destroying all the previously used markers using the this.markers array.

However the last x in the image has range as [[2,13],[2,14]] but still the green highlight is going all the way to the end. How do I keep it to highlight one column only?

CSS Classes

.addedText{
  background-color: #bbff99;
}

.removedText{
  background-color: #ffcccc;
}

#4

I don’t know if you can. You might have to be sneaky and add an extra space at the end of the inserted text, then subtract one character from the highlighted range.


#5

Why is that highlight is going over the marker range? (column are explicitly defined for the marker to obey)


#6

Ranges go left to right, top to bottom from the start Point to end Point. That’s the more natural and often useful behaviour.

I don’t think there’s an inbuilt rectangular range type.

Edit: I totally confused your range with being a row down, instead of a column across.


#7

I don’t actually know.


#8

Is there a link to the repo so we can see everything in context, and try it ourselves if needed?


#9

The range is from 3rd row 14th column till 3rd row 15th column. So it is actually column across.


#10

Hello.           :neutral_face: Sorry for the intrusion.

Would a package like split-diff be worth looking for, for inspiration?

@horcrux2301 - consider @Aerijo’s suggestion to share with him your repo. Send him a PM if you’d like. It is rare to have someone offer to help as he is doing.

Cheers.


#11

Hey @DamnedScholar @Aerijo @danPadric

I was busy with uni stuff for a few days, so couldn’t get back to you.

After reading docs and some other code of some other packages, I figured using a pane will be a best option. I can append the necessary diff as html code directly with proper class names to show relevant colors.

If anyone is interested the package I am developing is -> AFCP

You can find the relevant code here -> Add Pane and then view for the pane here View Code

Also thank you guys for the help. :slight_smile: