createSourceMark()



Have just added the first draft of "Goto definition" functionality to
the Nim GTK editor.

http://ssalewski.de/tmp/NEd-InputFont.png


Is it intended that createSourceMark() does only work when iter is at
the beginning of the line? For example, the code below does not
generate the visible mark (list add) as shown in the picture above when
I uncomment "discard iter.forwardChar". That behaviour may be ok, but
it was not clear to me reading the docs.

proc markLocation(view: var NimView; ln, cn: int) =
  var startIter, endIter, iter: TextIterObj
  view.freeErrors
  let buffer: gtksource.Buffer = gtksource.buffer(view.getBuffer)
  buffer.getStartIter(startIter)
  buffer.getEndIter(endIter)
  buffer.removeTagByName(ErrorTagName, startIter, endIter)
  for i in 0 .. MaxErrorTags:
    buffer.removeTagByName($i, startIter, endIter)
  buffer.removeSourceMarks(startIter, endIter, NullStr)
  view.showLinemarks = false
  var attrs = newMarkAttributes()
  var color = RGBAObj(red: 0.5, green: 0.5, blue: 0.5, alpha: 0.2)
  attrs.background = color
  attrs.iconName = "list-remove"
  view.setMarkAttributes(ErrorTagName, attrs, priority = 1)
  objectUnref(attrs)
  buffer.getIterAtLineIndex320(startIter, ln.cint, cn.cint)
  iter = startIter
  if iter.line == 0:
    discard iter.backwardLine
  else:
    discard iter.backwardLine
    discard iter.forwardLine
  #discard iter.forwardChar
  discard buffer.createSourceMark(NullStr, ErrorTagName, iter)
  let tag: TextTag = buffer.tagTable.lookup(ErrorTagName)
  assert(tag != nil)
  discard startiter.backwardChar
  if startIter.hasTag(tag):
    discard startIter.forwardToTagToggle(tag)
  discard startiter.forwardChar
  endIter = startIter
  iter = startIter
  discard iter.forwardToLineEnd
  discard endIter.forwardChar
  discard endIter.forwardFindChar(advanceErrorWord, userData = nil, limit = iter)
  buffer.applyTag(tag, startIter, endIter)
  view.showLinemarks = true


Another question, in the code above I needed 5 lines to move the cursor
at the start of the current line. Is there a simpler way?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]