Can I insert a zero-width tagged span in a GtkTextView?

57 views Asked by At

I have a GtkTextView in which I would like to have some non-editable spans embedded in an otherwise freely editable document. The problem is, if I delete all the text between two such spans, they "merge together", in the sense that I can no longer insert characters between them. Here's some ruby code demonstrating the problem:

require 'gtk3'

window = Gtk::Window.new("Text view")
window.set_size_request(800, 600)
window.signal_connect("delete-event") { |_widget| Gtk.main_quit }

textview = Gtk::TextView.new
buffer = textview.buffer
buffer.create_tag "locked", {"editable" => false, "background" => "light green"}
iter = buffer.get_iter_at_offset 0
buffer.insert iter, "hello", "locked"
buffer.insert iter, " "
buffer.insert iter, "world", "locked"

window.add(textview)
window.show_all
Gtk.main

Since I have added an editable " " between "hello" and "world", I can insert text between them, but if I delete the space I can no longer add it back, even though "hello" and "world" are two independent locked spans.

Edit: To clarify, by "delete the space" I mean if I click into the text area and hit backspace till the space goes away and the two uneditable spans join together, I can no longer click on the boundary between them and insert text to push them back apart.

1

There are 1 answers

1
ptomato On

You could try replacing the interstitial text with a zero-width space instead of deleting it.