19 import java.awt.{BorderLayout, Graphics, Color, Dimension, Graphics2D, Point} |
19 import java.awt.{BorderLayout, Graphics, Color, Dimension, Graphics2D, Point} |
20 import java.awt.event.{MouseAdapter, MouseMotionAdapter, MouseEvent, |
20 import java.awt.event.{MouseAdapter, MouseMotionAdapter, MouseEvent, |
21 FocusAdapter, FocusEvent, WindowEvent, WindowAdapter} |
21 FocusAdapter, FocusEvent, WindowEvent, WindowAdapter} |
22 import javax.swing.{JPanel, ToolTipManager, Popup, PopupFactory, SwingUtilities, BorderFactory} |
22 import javax.swing.{JPanel, ToolTipManager, Popup, PopupFactory, SwingUtilities, BorderFactory} |
23 import javax.swing.event.{CaretListener, CaretEvent} |
23 import javax.swing.event.{CaretListener, CaretEvent} |
24 import javax.swing.text.Segment |
|
25 |
24 |
26 import org.gjt.sp.util.Log |
25 import org.gjt.sp.util.Log |
27 |
26 |
28 import org.gjt.sp.jedit.{jEdit, OperatingSystem, Debug} |
27 import org.gjt.sp.jedit.{jEdit, OperatingSystem, Debug} |
29 import org.gjt.sp.jedit.gui.RolloverButton |
28 import org.gjt.sp.jedit.gui.RolloverButton |
315 |
314 |
316 |
315 |
317 /* caret range */ |
316 /* caret range */ |
318 |
317 |
319 def caret_range(): Text.Range = |
318 def caret_range(): Text.Range = |
320 { |
319 Isabelle.buffer_lock(model.buffer) { |
321 val buffer = model.buffer |
320 def text(i: Text.Offset): Char = model.buffer.getText(i, 1).charAt(0) |
322 Isabelle.buffer_lock(buffer) { |
321 val caret = text_area.getCaretPosition |
323 val max = buffer.getLength |
322 try { |
324 val text = new Segment; buffer.getText(0, max, text) |
323 val c = text(caret) |
325 val chars = BreakIterator.getCharacterInstance(); chars.setText(text) |
324 if (Character.isHighSurrogate(c) && Character.isLowSurrogate(text(caret + 1))) |
326 |
325 Text.Range(caret, caret + 2) |
327 val stop = chars.following(text_area.getCaretPosition) |
326 else if (Character.isLowSurrogate(c) && Character.isHighSurrogate(text(caret - 1))) |
328 if (stop < 0) Text.Range(max, max) |
327 Text.Range(caret - 1, caret + 1) |
329 else Text.Range(chars.previous(), stop) |
328 else Text.Range(caret, caret + 1) |
330 } |
329 } |
331 } |
330 catch { case _: ArrayIndexOutOfBoundsException => Text.Range(caret, caret + 1) } |
|
331 } |
332 |
332 |
333 |
333 |
334 /* caret handling */ |
334 /* caret handling */ |
335 |
335 |
336 def selected_command(): Option[Command] = |
336 def selected_command(): Option[Command] = |