确定行号之间是否存在偏移?

发布于 2024-08-26 07:40:11 字数 239 浏览 11 评论 0原文

我需要确定给定的选择是否位于起始线和结束线之间。 我有一个 ILineRange 和 Eclipse 视口内的给定偏移量。 (我需要知道,选择(来自远程方)是否是在本地用户的当前视口内进行的。不幸的是,我无法从选择中获取 ILineRange 。我必须依赖 getOffset( ) 和 getLength()...
有人有主意吗?
我认为对此没有一个干净的解决方案,因为偏移量(或每行的字符不同(新行行或一大块注释)。

I need to determine if a given selection is in between a start line and an end line.
I have an ILineRange and a given offset within the viewport of eclipse. (I need to know, if the selection (from a remote party) was made within the current viewport of the local user. Unfortunately, I cannot get an ILineRange from the selection. I must rely on getOffset() and getLength()...
Anyone has an idea?
I think there is not a clean solution for this, as the offset (or the characters per line vary (new line lines or a big block of comment).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素食主义者 2024-09-02 07:40:11

位置和偏移量之间的转换可以使用 IDocument 的 API(围绕 getLine*() 的方法)完成。 (我不确定我完全理解你的问题,但我确实希望这是有用的信息。)

The conversion between positions and offsets can be done with IDocument's API (methods around getLine*()). (I'm not sure I fully understood your question, but I do hope that this is helpful information.)

柳若烟 2024-09-02 07:40:11

也许你可以检查是否org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.STOverviewRuler 处理与您遇到的同类问题.
大致如下:

if (ANNOTATION_HEIGHT_SCALABLE) {
  int numbersOfLines= document.getNumberOfLines(annotationOffset, annotationLength);
  // don't count empty trailing lines
  IRegion lastLine= document.getLineInformationOfOffset(annotationOffset + annotationLength);
  if (lastLine.getOffset() == annotationOffset + annotationLength) {
    numbersOfLines -= 2;
    hh= (numbersOfLines * size.y) / maxLines + ANNOTATION_HEIGHT;
    if (hh < ANNOTATION_HEIGHT)
      hh= ANNOTATION_HEIGHT;
    } else
      hh= ANNOTATION_HEIGHT;
  }
  fAnnotationHeight= hh;

  int startLine= textWidget.getLineAtOffset(annotationOffset - visible.getOffset());
                        yy= Math.min((startLine * size.y) / maxLines, size.y - hh);

Maybe you can check if that org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.STOverviewRuler class deals with the same kind of problem you have.
Something along the lines of:

if (ANNOTATION_HEIGHT_SCALABLE) {
  int numbersOfLines= document.getNumberOfLines(annotationOffset, annotationLength);
  // don't count empty trailing lines
  IRegion lastLine= document.getLineInformationOfOffset(annotationOffset + annotationLength);
  if (lastLine.getOffset() == annotationOffset + annotationLength) {
    numbersOfLines -= 2;
    hh= (numbersOfLines * size.y) / maxLines + ANNOTATION_HEIGHT;
    if (hh < ANNOTATION_HEIGHT)
      hh= ANNOTATION_HEIGHT;
    } else
      hh= ANNOTATION_HEIGHT;
  }
  fAnnotationHeight= hh;

  int startLine= textWidget.getLineAtOffset(annotationOffset - visible.getOffset());
                        yy= Math.min((startLine * size.y) / maxLines, size.y - hh);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文