author | wenzelm |
Fri, 15 Nov 2024 16:50:44 +0100 | |
changeset 81453 | b99b531f13e6 |
parent 81450 | 0c29878ae48f |
child 81461 | b82ee80baa05 |
permissions | -rw-r--r-- |
49406 | 1 |
/* Title: Tools/jEdit/src/jedit_lib.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Misc library functions for jEdit. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle.jedit |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
65469 | 12 |
import java.io.{File => JFile} |
72899 | 13 |
import java.awt.{Component, Container, GraphicsEnvironment, Point, Rectangle, Dimension, Toolkit} |
53784 | 14 |
import java.awt.event.{InputEvent, KeyEvent, KeyListener} |
81450
0c29878ae48f
more accurate initial FontRenderContext, notably on macOS, Windows, or Linux with "env GDK_SCALE=2";
wenzelm
parents:
81444
diff
changeset
|
15 |
import java.awt.font.FontRenderContext |
81434
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
16 |
import javax.swing.{Icon, ImageIcon, JScrollBar, JWindow, SwingUtilities} |
49710
21d88a631fcc
refer to parent frame -- relevant for floating dockables in particular;
wenzelm
parents:
49409
diff
changeset
|
17 |
|
56823
37be55461dbe
more frugal access to theory text via Reader, reduced costs for I/O text decoding;
wenzelm
parents:
56774
diff
changeset
|
18 |
import scala.util.parsing.input.CharSequenceReader |
73354 | 19 |
import scala.jdk.CollectionConverters._ |
81426
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
20 |
import scala.annotation.tailrec |
49406 | 21 |
|
62264
340f98836fd9
re-init document views for the sake of Text_Overview size;
wenzelm
parents:
61865
diff
changeset
|
22 |
import org.gjt.sp.jedit.{jEdit, Buffer, View, GUIUtilities, Debug, EditPane} |
72927
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72899
diff
changeset
|
23 |
import org.gjt.sp.jedit.io.{FileVFS, VFSManager} |
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72899
diff
changeset
|
24 |
import org.gjt.sp.jedit.gui.{KeyEventWorkaround, KeyEventTranslator} |
61192 | 25 |
import org.gjt.sp.jedit.buffer.{JEditBuffer, LineManager} |
81450
0c29878ae48f
more accurate initial FontRenderContext, notably on macOS, Windows, or Linux with "env GDK_SCALE=2";
wenzelm
parents:
81444
diff
changeset
|
26 |
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaPainter, Selection, AntiAlias} |
49406 | 27 |
|
28 |
||
75393 | 29 |
object JEdit_Lib { |
71861 | 30 |
/* jEdit directories */ |
31 |
||
32 |
def directories: List[JFile] = |
|
33 |
(Option(jEdit.getSettingsDirectory).toList ::: List(jEdit.getJEditHome)).map(new JFile(_)) |
|
34 |
||
35 |
||
53019 | 36 |
/* window geometry measurement */ |
37 |
||
38 |
private lazy val dummy_window = new JWindow |
|
39 |
||
75393 | 40 |
final case class Window_Geometry(width: Int, height: Int, inner_width: Int, inner_height: Int) { |
53019 | 41 |
def deco_width: Int = width - inner_width |
42 |
def deco_height: Int = height - inner_height |
|
43 |
} |
|
44 |
||
75393 | 45 |
def window_geometry(outer: Container, inner: Component): Window_Geometry = { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56930
diff
changeset
|
46 |
GUI_Thread.require {} |
53019 | 47 |
|
48 |
val old_content = dummy_window.getContentPane |
|
49 |
||
50 |
dummy_window.setContentPane(outer) |
|
81401 | 51 |
dummy_window.pack() |
73367 | 52 |
dummy_window.revalidate() |
53019 | 53 |
|
54 |
val geometry = |
|
55 |
Window_Geometry( |
|
56 |
dummy_window.getWidth, dummy_window.getHeight, inner.getWidth, inner.getHeight) |
|
57 |
||
58 |
dummy_window.setContentPane(old_content) |
|
59 |
||
60 |
geometry |
|
61 |
} |
|
62 |
||
63 |
||
76782 | 64 |
/* plain files */ |
65469 | 65 |
|
66 |
def is_file(name: String): Boolean = |
|
76782 | 67 |
name != null && name.nonEmpty && VFSManager.getVFSForPath(name).isInstanceOf[FileVFS] |
65469 | 68 |
|
69 |
def check_file(name: String): Option[JFile] = |
|
70 |
if (is_file(name)) Some(new JFile(name)) else None |
|
71 |
||
72 |
||
49406 | 73 |
/* buffers */ |
74 |
||
75 |
def buffer_text(buffer: JEditBuffer): String = |
|
76 |
buffer_lock(buffer) { buffer.getText(0, buffer.getLength) } |
|
77 |
||
56823
37be55461dbe
more frugal access to theory text via Reader, reduced costs for I/O text decoding;
wenzelm
parents:
56774
diff
changeset
|
78 |
def buffer_reader(buffer: JEditBuffer): CharSequenceReader = |
64824 | 79 |
Scan.char_reader(buffer.getSegment(0, buffer.getLength)) |
56823
37be55461dbe
more frugal access to theory text via Reader, reduced costs for I/O text decoding;
wenzelm
parents:
56774
diff
changeset
|
80 |
|
75393 | 81 |
def buffer_mode(buffer: JEditBuffer): String = { |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53247
diff
changeset
|
82 |
val mode = buffer.getMode |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53247
diff
changeset
|
83 |
if (mode == null) "" |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53247
diff
changeset
|
84 |
else { |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53247
diff
changeset
|
85 |
val name = mode.getName |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53247
diff
changeset
|
86 |
if (name == null) "" else name |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53247
diff
changeset
|
87 |
} |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53247
diff
changeset
|
88 |
} |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53247
diff
changeset
|
89 |
|
65469 | 90 |
def buffer_line_manager(buffer: JEditBuffer): LineManager = |
91 |
Untyped.get[LineManager](buffer, "lineMgr") |
|
92 |
||
49406 | 93 |
def buffer_name(buffer: Buffer): String = buffer.getSymlinkPath |
94 |
||
65469 | 95 |
def buffer_file(buffer: Buffer): Option[JFile] = check_file(buffer_name(buffer)) |
61192 | 96 |
|
49406 | 97 |
|
98 |
/* main jEdit components */ |
|
99 |
||
73354 | 100 |
def jedit_buffers(): Iterator[Buffer] = |
101 |
jEdit.getBufferManager().getBuffers().asScala.iterator |
|
49406 | 102 |
|
103 |
def jedit_buffer(name: String): Option[Buffer] = |
|
104 |
jedit_buffers().find(buffer => buffer_name(buffer) == name) |
|
105 |
||
56457
eea4bbe15745
tuned signature -- prefer static type Document.Node.Name;
wenzelm
parents:
55812
diff
changeset
|
106 |
def jedit_buffer(name: Document.Node.Name): Option[Buffer] = |
eea4bbe15745
tuned signature -- prefer static type Document.Node.Name;
wenzelm
parents:
55812
diff
changeset
|
107 |
jedit_buffer(name.node) |
eea4bbe15745
tuned signature -- prefer static type Document.Node.Name;
wenzelm
parents:
55812
diff
changeset
|
108 |
|
73354 | 109 |
def jedit_views(): Iterator[View] = |
110 |
jEdit.getViewManager().getViews().asScala.iterator |
|
49406 | 111 |
|
69636 | 112 |
def jedit_view(view: View = null): View = |
113 |
if (view == null) jEdit.getActiveView() else view |
|
114 |
||
62264
340f98836fd9
re-init document views for the sake of Text_Overview size;
wenzelm
parents:
61865
diff
changeset
|
115 |
def jedit_edit_panes(view: View): Iterator[EditPane] = |
340f98836fd9
re-init document views for the sake of Text_Overview size;
wenzelm
parents:
61865
diff
changeset
|
116 |
if (view == null) Iterator.empty |
340f98836fd9
re-init document views for the sake of Text_Overview size;
wenzelm
parents:
61865
diff
changeset
|
117 |
else view.getEditPanes().iterator.filter(_ != null) |
340f98836fd9
re-init document views for the sake of Text_Overview size;
wenzelm
parents:
61865
diff
changeset
|
118 |
|
49406 | 119 |
def jedit_text_areas(view: View): Iterator[JEditTextArea] = |
56587
83777a91f5de
clarified before_caret_range: prevent continuation on next line;
wenzelm
parents:
56574
diff
changeset
|
120 |
if (view == null) Iterator.empty |
83777a91f5de
clarified before_caret_range: prevent continuation on next line;
wenzelm
parents:
56574
diff
changeset
|
121 |
else view.getEditPanes().iterator.filter(_ != null).map(_.getTextArea).filter(_ != null) |
49406 | 122 |
|
123 |
def jedit_text_areas(): Iterator[JEditTextArea] = |
|
71601 | 124 |
jedit_views().flatMap(jedit_text_areas) |
49406 | 125 |
|
126 |
def jedit_text_areas(buffer: JEditBuffer): Iterator[JEditTextArea] = |
|
127 |
jedit_text_areas().filter(_.getBuffer == buffer) |
|
128 |
||
75393 | 129 |
def buffer_lock[A](buffer: JEditBuffer)(body: => A): A = { |
49406 | 130 |
try { buffer.readLock(); body } |
131 |
finally { buffer.readUnlock() } |
|
132 |
} |
|
49407 | 133 |
|
75393 | 134 |
def buffer_edit[A](buffer: JEditBuffer)(body: => A): A = { |
50195
863b1dfc396c
prefer buffer_edit combinator over Java-style boilerplate;
wenzelm
parents:
50186
diff
changeset
|
135 |
try { buffer.beginCompoundEdit(); body } |
863b1dfc396c
prefer buffer_edit combinator over Java-style boilerplate;
wenzelm
parents:
50186
diff
changeset
|
136 |
finally { buffer.endCompoundEdit() } |
863b1dfc396c
prefer buffer_edit combinator over Java-style boilerplate;
wenzelm
parents:
50186
diff
changeset
|
137 |
} |
863b1dfc396c
prefer buffer_edit combinator over Java-style boilerplate;
wenzelm
parents:
50186
diff
changeset
|
138 |
|
49407 | 139 |
|
81423
056657540039
clarified signature: inline org.gjt.sp.jedit.textarea.TextArea.setText();
wenzelm
parents:
81417
diff
changeset
|
140 |
/* buffer text */ |
50215 | 141 |
|
67014 | 142 |
def get_text(buffer: JEditBuffer, range: Text.Range): Option[String] = |
50215 | 143 |
try { Some(buffer.getText(range.start, range.length)) } |
144 |
catch { case _: ArrayIndexOutOfBoundsException => None } |
|
145 |
||
81435
839c4b2b01fa
more ambitious scrolling: retain original scroll position if possible;
wenzelm
parents:
81434
diff
changeset
|
146 |
def set_text(buffer: JEditBuffer, text: List[String]): Int = { |
81423
056657540039
clarified signature: inline org.gjt.sp.jedit.textarea.TextArea.setText();
wenzelm
parents:
81417
diff
changeset
|
147 |
val old = buffer.isUndoInProgress |
056657540039
clarified signature: inline org.gjt.sp.jedit.textarea.TextArea.setText();
wenzelm
parents:
81417
diff
changeset
|
148 |
def set(b: Boolean): Unit = Untyped.set[Boolean](buffer, "undoInProgress", b) |
81426
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
149 |
|
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
150 |
val length = buffer.getLength |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
151 |
var offset = 0 |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
152 |
|
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
153 |
@tailrec def drop_common_prefix(list: List[String]): List[String] = |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
154 |
list match { |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
155 |
case s :: rest |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
156 |
if offset + s.length <= length && |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
157 |
CharSequence.compare(buffer.getSegment(offset, s.length), s) == 0 => |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
158 |
offset += s.length |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
159 |
drop_common_prefix(rest) |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
160 |
case _ => list |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
161 |
} |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
162 |
|
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
163 |
def insert(list: List[String]): Unit = |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
164 |
for (s <- list) { |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
165 |
buffer.insert(offset, s) |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
166 |
offset += s.length |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
167 |
} |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
168 |
|
81423
056657540039
clarified signature: inline org.gjt.sp.jedit.textarea.TextArea.setText();
wenzelm
parents:
81417
diff
changeset
|
169 |
try { |
056657540039
clarified signature: inline org.gjt.sp.jedit.textarea.TextArea.setText();
wenzelm
parents:
81417
diff
changeset
|
170 |
set(true) |
056657540039
clarified signature: inline org.gjt.sp.jedit.textarea.TextArea.setText();
wenzelm
parents:
81417
diff
changeset
|
171 |
buffer.beginCompoundEdit() |
81426
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
172 |
val rest = drop_common_prefix(text) |
81435
839c4b2b01fa
more ambitious scrolling: retain original scroll position if possible;
wenzelm
parents:
81434
diff
changeset
|
173 |
val update_start = offset |
81426
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
174 |
if (offset < length) buffer.remove(offset, length - offset) |
56bab51e02c1
performance tuning: more incremental update of buffer content;
wenzelm
parents:
81423
diff
changeset
|
175 |
insert(rest) |
81435
839c4b2b01fa
more ambitious scrolling: retain original scroll position if possible;
wenzelm
parents:
81434
diff
changeset
|
176 |
update_start |
81423
056657540039
clarified signature: inline org.gjt.sp.jedit.textarea.TextArea.setText();
wenzelm
parents:
81417
diff
changeset
|
177 |
} |
056657540039
clarified signature: inline org.gjt.sp.jedit.textarea.TextArea.setText();
wenzelm
parents:
81417
diff
changeset
|
178 |
finally { |
056657540039
clarified signature: inline org.gjt.sp.jedit.textarea.TextArea.setText();
wenzelm
parents:
81417
diff
changeset
|
179 |
buffer.endCompoundEdit() |
056657540039
clarified signature: inline org.gjt.sp.jedit.textarea.TextArea.setText();
wenzelm
parents:
81417
diff
changeset
|
180 |
set(old) |
056657540039
clarified signature: inline org.gjt.sp.jedit.textarea.TextArea.setText();
wenzelm
parents:
81417
diff
changeset
|
181 |
} |
056657540039
clarified signature: inline org.gjt.sp.jedit.textarea.TextArea.setText();
wenzelm
parents:
81417
diff
changeset
|
182 |
} |
056657540039
clarified signature: inline org.gjt.sp.jedit.textarea.TextArea.setText();
wenzelm
parents:
81417
diff
changeset
|
183 |
|
50215 | 184 |
|
49407 | 185 |
/* point range */ |
186 |
||
187 |
def point_range(buffer: JEditBuffer, offset: Text.Offset): Text.Range = |
|
56592
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
188 |
if (offset < 0) Text.Range.offside |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
189 |
else |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
190 |
buffer_lock(buffer) { |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
191 |
def text(i: Text.Offset): Char = buffer.getText(i, 1).charAt(0) |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
192 |
try { |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
193 |
val c = text(offset) |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
194 |
if (Character.isHighSurrogate(c) && Character.isLowSurrogate(text(offset + 1))) |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
195 |
Text.Range(offset, offset + 2) |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
196 |
else if (Character.isLowSurrogate(c) && Character.isHighSurrogate(text(offset - 1))) |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
197 |
Text.Range(offset - 1, offset + 1) |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
198 |
else |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
199 |
Text.Range(offset, offset + 1) |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
200 |
} |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
201 |
catch { case _: ArrayIndexOutOfBoundsException => Text.Range(offset, offset + 1) } |
49407 | 202 |
} |
49408 | 203 |
|
204 |
||
55812 | 205 |
/* text ranges */ |
206 |
||
207 |
def buffer_range(buffer: JEditBuffer): Text.Range = |
|
208 |
Text.Range(0, buffer.getLength) |
|
49408 | 209 |
|
56587
83777a91f5de
clarified before_caret_range: prevent continuation on next line;
wenzelm
parents:
56574
diff
changeset
|
210 |
def line_range(buffer: JEditBuffer, line: Int): Text.Range = |
56589
71c5d1f516c0
more robust JEdit_Lib.line_range, according to usual jEdit confusion at end of last line;
wenzelm
parents:
56587
diff
changeset
|
211 |
Text.Range(buffer.getLineStartOffset(line), buffer.getLineEndOffset(line) min buffer.getLength) |
56587
83777a91f5de
clarified before_caret_range: prevent continuation on next line;
wenzelm
parents:
56574
diff
changeset
|
212 |
|
56592
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
213 |
def caret_range(text_area: TextArea): Text.Range = |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
214 |
point_range(text_area.getBuffer, text_area.getCaretPosition) |
5157f7615e99
prefer direct caret_range for update_dictionary actions, which usually happen outside the flow of editing;
wenzelm
parents:
56589
diff
changeset
|
215 |
|
81299 | 216 |
def selection_ranges(text_area: TextArea): List[Text.Range] = { |
217 |
val buffer = text_area.getBuffer |
|
218 |
text_area.getSelection.toList.flatMap( |
|
219 |
{ |
|
220 |
case rect: Selection.Rect => |
|
221 |
List.from( |
|
222 |
for { |
|
223 |
l <- (rect.getStartLine to rect.getEndLine).iterator |
|
224 |
r = Text.Range(rect.getStart(buffer, l), rect.getEnd(buffer, l)) |
|
225 |
if !r.is_singularity |
|
226 |
} yield r) |
|
227 |
case sel: Selection => List(Text.Range(sel.getStart, sel.getEnd)) |
|
228 |
}) |
|
229 |
} |
|
230 |
||
75393 | 231 |
def visible_range(text_area: TextArea): Option[Text.Range] = { |
49408 | 232 |
val buffer = text_area.getBuffer |
233 |
val n = text_area.getVisibleLines |
|
234 |
if (n > 0) { |
|
235 |
val start = text_area.getScreenLineStartOffset(0) |
|
236 |
val raw_end = text_area.getScreenLineEndOffset(n - 1) |
|
49843
afddf4e26fac
further refinement of jEdit line range, avoiding lack of final \n;
wenzelm
parents:
49712
diff
changeset
|
237 |
val end = if (raw_end >= 0) raw_end min buffer.getLength else buffer.getLength |
afddf4e26fac
further refinement of jEdit line range, avoiding lack of final \n;
wenzelm
parents:
49712
diff
changeset
|
238 |
Some(Text.Range(start, end)) |
49408 | 239 |
} |
240 |
else None |
|
241 |
} |
|
242 |
||
75393 | 243 |
def invalidate_range(text_area: TextArea, range: Text.Range): Unit = { |
49408 | 244 |
val buffer = text_area.getBuffer |
55812 | 245 |
buffer_range(buffer).try_restrict(range) match { |
246 |
case Some(range1) if !range1.is_singularity => |
|
56699 | 247 |
try { |
248 |
text_area.invalidateLineRange( |
|
249 |
buffer.getLineOfOffset(range1.start), |
|
250 |
buffer.getLineOfOffset(range1.stop)) |
|
251 |
} |
|
252 |
catch { case _: ArrayIndexOutOfBoundsException => } |
|
55812 | 253 |
case _ => |
254 |
} |
|
49408 | 255 |
} |
49409 | 256 |
|
80554 | 257 |
def invalidate_screen(text_area: TextArea, start: Int = -1, end: Int = -1): Unit = { |
62986 | 258 |
val visible_lines = text_area.getVisibleLines |
80551 | 259 |
if (visible_lines > 0) { |
80554 | 260 |
val start_line = if (start >= 0) start else 0 |
261 |
val end_line = if (end >= 0) end else visible_lines |
|
262 |
text_area.invalidateScreenLineRange(start_line, end_line) |
|
80551 | 263 |
} |
62986 | 264 |
} |
265 |
||
49409 | 266 |
|
81434
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
267 |
/* scrolling */ |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
268 |
|
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
269 |
def vertical_scrollbar(text_area: TextArea): JScrollBar = |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
270 |
Untyped.get[JScrollBar](text_area, "vertical") |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
271 |
|
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
272 |
def horizontal_scrollbar(text_area: TextArea): JScrollBar = |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
273 |
Untyped.get[JScrollBar](text_area, "horizontal") |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
274 |
|
81435
839c4b2b01fa
more ambitious scrolling: retain original scroll position if possible;
wenzelm
parents:
81434
diff
changeset
|
275 |
def scrollbar_at_end(scrollbar: JScrollBar): Boolean = |
839c4b2b01fa
more ambitious scrolling: retain original scroll position if possible;
wenzelm
parents:
81434
diff
changeset
|
276 |
scrollbar.getValue > 0 && |
839c4b2b01fa
more ambitious scrolling: retain original scroll position if possible;
wenzelm
parents:
81434
diff
changeset
|
277 |
scrollbar.getValue + scrollbar.getVisibleAmount == scrollbar.getMaximum |
839c4b2b01fa
more ambitious scrolling: retain original scroll position if possible;
wenzelm
parents:
81434
diff
changeset
|
278 |
|
839c4b2b01fa
more ambitious scrolling: retain original scroll position if possible;
wenzelm
parents:
81434
diff
changeset
|
279 |
def scrollbar_bottom(text_area: TextArea): Boolean = |
839c4b2b01fa
more ambitious scrolling: retain original scroll position if possible;
wenzelm
parents:
81434
diff
changeset
|
280 |
scrollbar_at_end(vertical_scrollbar(text_area)) |
839c4b2b01fa
more ambitious scrolling: retain original scroll position if possible;
wenzelm
parents:
81434
diff
changeset
|
281 |
|
839c4b2b01fa
more ambitious scrolling: retain original scroll position if possible;
wenzelm
parents:
81434
diff
changeset
|
282 |
def scrollbar_start(text_area: TextArea): Int = |
839c4b2b01fa
more ambitious scrolling: retain original scroll position if possible;
wenzelm
parents:
81434
diff
changeset
|
283 |
text_area.getBuffer.getLineStartOffset(vertical_scrollbar(text_area).getValue) |
81434
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
284 |
|
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
285 |
def bottom_line_offset(buffer: JEditBuffer): Int = |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
286 |
buffer.getLineStartOffset(buffer.getLineOfOffset(buffer.getLength)) |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
287 |
|
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
288 |
def scroll_to_caret(text_area: TextArea): Unit = { |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
289 |
val caret_line = text_area.getCaretLine() |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
290 |
val display_manager = text_area.getDisplayManager |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
291 |
if (!display_manager.isLineVisible(caret_line)) { |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
292 |
display_manager.expandFold(caret_line, true) |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
293 |
} |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
294 |
text_area.scrollToCaret(true) |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
295 |
} |
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
296 |
|
1935ed4fe9c2
more ambitious scrolling: retain bottom position after output;
wenzelm
parents:
81426
diff
changeset
|
297 |
|
81453 | 298 |
/* font */ |
49409 | 299 |
|
81450
0c29878ae48f
more accurate initial FontRenderContext, notably on macOS, Windows, or Linux with "env GDK_SCALE=2";
wenzelm
parents:
81444
diff
changeset
|
300 |
def init_font_context(view: View, painter: TextAreaPainter): Unit = { |
0c29878ae48f
more accurate initial FontRenderContext, notably on macOS, Windows, or Linux with "env GDK_SCALE=2";
wenzelm
parents:
81444
diff
changeset
|
301 |
painter.setAntiAlias(new AntiAlias(jEdit.getProperty("view.antiAlias"))) |
0c29878ae48f
more accurate initial FontRenderContext, notably on macOS, Windows, or Linux with "env GDK_SCALE=2";
wenzelm
parents:
81444
diff
changeset
|
302 |
painter.setFractionalFontMetricsEnabled(jEdit.getBooleanProperty("view.fracFontMetrics")) |
0c29878ae48f
more accurate initial FontRenderContext, notably on macOS, Windows, or Linux with "env GDK_SCALE=2";
wenzelm
parents:
81444
diff
changeset
|
303 |
val old = painter.getFontRenderContext |
0c29878ae48f
more accurate initial FontRenderContext, notably on macOS, Windows, or Linux with "env GDK_SCALE=2";
wenzelm
parents:
81444
diff
changeset
|
304 |
Untyped.set[FontRenderContext](painter, "fontRenderContext", |
0c29878ae48f
more accurate initial FontRenderContext, notably on macOS, Windows, or Linux with "env GDK_SCALE=2";
wenzelm
parents:
81444
diff
changeset
|
305 |
new FontRenderContext(view.getGraphicsConfiguration.getDefaultTransform, |
0c29878ae48f
more accurate initial FontRenderContext, notably on macOS, Windows, or Linux with "env GDK_SCALE=2";
wenzelm
parents:
81444
diff
changeset
|
306 |
old.getAntiAliasingHint, old.getFractionalMetricsHint)) |
0c29878ae48f
more accurate initial FontRenderContext, notably on macOS, Windows, or Linux with "env GDK_SCALE=2";
wenzelm
parents:
81444
diff
changeset
|
307 |
} |
0c29878ae48f
more accurate initial FontRenderContext, notably on macOS, Windows, or Linux with "env GDK_SCALE=2";
wenzelm
parents:
81444
diff
changeset
|
308 |
|
81340 | 309 |
def font_metric(painter: TextAreaPainter): Font_Metric = |
81412
4794576828df
clarified signature: include standard margin in object equality;
wenzelm
parents:
81401
diff
changeset
|
310 |
new Font_Metric( |
4794576828df
clarified signature: include standard margin in object equality;
wenzelm
parents:
81401
diff
changeset
|
311 |
font = painter.getFont, |
81417
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81412
diff
changeset
|
312 |
context = painter.getFontRenderContext) |
81340 | 313 |
|
81453 | 314 |
|
315 |
/* graphics range */ |
|
316 |
||
60215 | 317 |
case class Gfx_Range(x: Int, y: Int, length: Int) |
49409 | 318 |
|
49843
afddf4e26fac
further refinement of jEdit line range, avoiding lack of final \n;
wenzelm
parents:
49712
diff
changeset
|
319 |
// NB: jEdit always normalizes \r\n and \r to \n |
49409 | 320 |
// NB: last line lacks \n |
75393 | 321 |
def gfx_range(text_area: TextArea, range: Text.Range): Option[Gfx_Range] = { |
81340 | 322 |
val metric = font_metric(text_area.getPainter) |
323 |
val char_width = metric.average_width.round.toInt |
|
50849 | 324 |
|
49409 | 325 |
val buffer = text_area.getBuffer |
326 |
||
327 |
val end = buffer.getLength |
|
328 |
val stop = range.stop |
|
51078
4e1c940b1fb2
more robust JEdit_Lib.pixel_range, which could crash via Rich_Text_Area.tooltip_painter with bad mouse coordinates;
wenzelm
parents:
50849
diff
changeset
|
329 |
|
4e1c940b1fb2
more robust JEdit_Lib.pixel_range, which could crash via Rich_Text_Area.tooltip_painter with bad mouse coordinates;
wenzelm
parents:
50849
diff
changeset
|
330 |
val (p, q, r) = |
4e1c940b1fb2
more robust JEdit_Lib.pixel_range, which could crash via Rich_Text_Area.tooltip_painter with bad mouse coordinates;
wenzelm
parents:
50849
diff
changeset
|
331 |
try { |
4e1c940b1fb2
more robust JEdit_Lib.pixel_range, which could crash via Rich_Text_Area.tooltip_painter with bad mouse coordinates;
wenzelm
parents:
50849
diff
changeset
|
332 |
val p = text_area.offsetToXY(range.start) |
4e1c940b1fb2
more robust JEdit_Lib.pixel_range, which could crash via Rich_Text_Area.tooltip_painter with bad mouse coordinates;
wenzelm
parents:
50849
diff
changeset
|
333 |
val (q, r) = |
81401 | 334 |
if (get_text(buffer, Text.Range(stop - 1, stop)).contains("\n")) { |
51078
4e1c940b1fb2
more robust JEdit_Lib.pixel_range, which could crash via Rich_Text_Area.tooltip_painter with bad mouse coordinates;
wenzelm
parents:
50849
diff
changeset
|
335 |
(text_area.offsetToXY(stop - 1), char_width) |
81401 | 336 |
} |
337 |
else if (stop >= end) { |
|
55549
5c40782f68b3
clarified special eol treatment (amending 3d55ef732cd7): allow last line to be empty, which means stop == end for second-last line;
wenzelm
parents:
53786
diff
changeset
|
338 |
(text_area.offsetToXY(end), char_width * (stop - end)) |
81401 | 339 |
} |
51078
4e1c940b1fb2
more robust JEdit_Lib.pixel_range, which could crash via Rich_Text_Area.tooltip_painter with bad mouse coordinates;
wenzelm
parents:
50849
diff
changeset
|
340 |
else (text_area.offsetToXY(stop), 0) |
4e1c940b1fb2
more robust JEdit_Lib.pixel_range, which could crash via Rich_Text_Area.tooltip_painter with bad mouse coordinates;
wenzelm
parents:
50849
diff
changeset
|
341 |
(p, q, r) |
4e1c940b1fb2
more robust JEdit_Lib.pixel_range, which could crash via Rich_Text_Area.tooltip_painter with bad mouse coordinates;
wenzelm
parents:
50849
diff
changeset
|
342 |
} |
4e1c940b1fb2
more robust JEdit_Lib.pixel_range, which could crash via Rich_Text_Area.tooltip_painter with bad mouse coordinates;
wenzelm
parents:
50849
diff
changeset
|
343 |
catch { case _: ArrayIndexOutOfBoundsException => (null, null, 0) } |
49409 | 344 |
|
81401 | 345 |
if (p != null && q != null && p.x < q.x + r && p.y == q.y) { |
50115 | 346 |
Some(Gfx_Range(p.x, p.y, q.x + r - p.x)) |
81401 | 347 |
} |
49409 | 348 |
else None |
349 |
} |
|
49941
f2db0596bd61
more precise pixel_range: avoid popup when pointing into empty space after actual end-of-line;
wenzelm
parents:
49843
diff
changeset
|
350 |
|
f2db0596bd61
more precise pixel_range: avoid popup when pointing into empty space after actual end-of-line;
wenzelm
parents:
49843
diff
changeset
|
351 |
|
f2db0596bd61
more precise pixel_range: avoid popup when pointing into empty space after actual end-of-line;
wenzelm
parents:
49843
diff
changeset
|
352 |
/* pixel range */ |
f2db0596bd61
more precise pixel_range: avoid popup when pointing into empty space after actual end-of-line;
wenzelm
parents:
49843
diff
changeset
|
353 |
|
75393 | 354 |
def pixel_range(text_area: TextArea, x: Int, y: Int): Option[Text.Range] = { |
53183
018d71bee930
strict checking of coordinates wrt. inner painter component;
wenzelm
parents:
53019
diff
changeset
|
355 |
// coordinates wrt. inner painter component |
018d71bee930
strict checking of coordinates wrt. inner painter component;
wenzelm
parents:
53019
diff
changeset
|
356 |
val painter = text_area.getPainter |
018d71bee930
strict checking of coordinates wrt. inner painter component;
wenzelm
parents:
53019
diff
changeset
|
357 |
if (0 <= x && x < painter.getWidth && 0 <= y && y < painter.getHeight) { |
018d71bee930
strict checking of coordinates wrt. inner painter component;
wenzelm
parents:
53019
diff
changeset
|
358 |
val offset = text_area.xyToOffset(x, y, false) |
018d71bee930
strict checking of coordinates wrt. inner painter component;
wenzelm
parents:
53019
diff
changeset
|
359 |
if (offset >= 0) { |
018d71bee930
strict checking of coordinates wrt. inner painter component;
wenzelm
parents:
53019
diff
changeset
|
360 |
val range = point_range(text_area.getBuffer, offset) |
018d71bee930
strict checking of coordinates wrt. inner painter component;
wenzelm
parents:
53019
diff
changeset
|
361 |
gfx_range(text_area, range) match { |
60215 | 362 |
case Some(g) if g.x <= x && x < g.x + g.length => Some(range) |
53183
018d71bee930
strict checking of coordinates wrt. inner painter component;
wenzelm
parents:
53019
diff
changeset
|
363 |
case _ => None |
018d71bee930
strict checking of coordinates wrt. inner painter component;
wenzelm
parents:
53019
diff
changeset
|
364 |
} |
018d71bee930
strict checking of coordinates wrt. inner painter component;
wenzelm
parents:
53019
diff
changeset
|
365 |
} |
018d71bee930
strict checking of coordinates wrt. inner painter component;
wenzelm
parents:
53019
diff
changeset
|
366 |
else None |
49941
f2db0596bd61
more precise pixel_range: avoid popup when pointing into empty space after actual end-of-line;
wenzelm
parents:
49843
diff
changeset
|
367 |
} |
53183
018d71bee930
strict checking of coordinates wrt. inner painter component;
wenzelm
parents:
53019
diff
changeset
|
368 |
else None |
49941
f2db0596bd61
more precise pixel_range: avoid popup when pointing into empty space after actual end-of-line;
wenzelm
parents:
49843
diff
changeset
|
369 |
} |
51492
eaa1c4cc1106
more explicit Pretty.Metric, with clear distinction of unit (space width) vs. average char width (for visual adjustments) -- NB: Pretty formatting works via full space characters (despite a981a5c8a505 and 70f7483df9cb);
wenzelm
parents:
51469
diff
changeset
|
370 |
|
eaa1c4cc1106
more explicit Pretty.Metric, with clear distinction of unit (space width) vs. average char width (for visual adjustments) -- NB: Pretty formatting works via full space characters (despite a981a5c8a505 and 70f7483df9cb);
wenzelm
parents:
51469
diff
changeset
|
371 |
|
52873 | 372 |
/* icons */ |
373 |
||
75393 | 374 |
def load_icon(name: String): Icon = { |
52873 | 375 |
val name1 = |
376 |
if (name.startsWith("idea-icons/")) { |
|
75701 | 377 |
val file = File.uri(Path.explode("$ISABELLE_IDEA_ICONS")).toASCIIString |
52873 | 378 |
"jar:" + file + "!/" + name |
379 |
} |
|
380 |
else name |
|
381 |
val icon = GUIUtilities.loadIcon(name1) |
|
382 |
if (icon.getIconWidth < 0 || icon.getIconHeight < 0) error("Bad icon: " + name) |
|
383 |
else icon |
|
384 |
} |
|
52874 | 385 |
|
386 |
def load_image_icon(name: String): ImageIcon = |
|
387 |
load_icon(name) match { |
|
388 |
case icon: ImageIcon => icon |
|
389 |
case _ => error("Bad image icon: " + name) |
|
390 |
} |
|
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53183
diff
changeset
|
391 |
|
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53183
diff
changeset
|
392 |
|
53231
423e29f1f304
avoid complication and event duplication due to KeyEventInterceptor -- NB: popup has focus within root window, it is closed on loss of focus;
wenzelm
parents:
53226
diff
changeset
|
393 |
/* key event handling */ |
423e29f1f304
avoid complication and event duplication due to KeyEventInterceptor -- NB: popup has focus within root window, it is closed on loss of focus;
wenzelm
parents:
53226
diff
changeset
|
394 |
|
75393 | 395 |
def request_focus_view(alt_view: View = null): Unit = { |
73987
fc363a3b690a
build.props for isabelle.jar, including isabelle.jedit;
wenzelm
parents:
73652
diff
changeset
|
396 |
val view = if (alt_view != null) alt_view else jEdit.getActiveView() |
fc363a3b690a
build.props for isabelle.jar, including isabelle.jedit;
wenzelm
parents:
73652
diff
changeset
|
397 |
if (view != null) { |
fc363a3b690a
build.props for isabelle.jar, including isabelle.jedit;
wenzelm
parents:
73652
diff
changeset
|
398 |
val text_area = view.getTextArea |
fc363a3b690a
build.props for isabelle.jar, including isabelle.jedit;
wenzelm
parents:
73652
diff
changeset
|
399 |
if (text_area != null) text_area.requestFocus() |
fc363a3b690a
build.props for isabelle.jar, including isabelle.jedit;
wenzelm
parents:
73652
diff
changeset
|
400 |
} |
fc363a3b690a
build.props for isabelle.jar, including isabelle.jedit;
wenzelm
parents:
73652
diff
changeset
|
401 |
} |
66592 | 402 |
|
75393 | 403 |
def propagate_key(view: View, evt: KeyEvent): Unit = { |
53231
423e29f1f304
avoid complication and event duplication due to KeyEventInterceptor -- NB: popup has focus within root window, it is closed on loss of focus;
wenzelm
parents:
53226
diff
changeset
|
404 |
if (view != null && !evt.isConsumed) |
423e29f1f304
avoid complication and event duplication due to KeyEventInterceptor -- NB: popup has focus within root window, it is closed on loss of focus;
wenzelm
parents:
53226
diff
changeset
|
405 |
view.getInputHandler().processKeyEvent(evt, View.ACTION_BAR, false) |
423e29f1f304
avoid complication and event duplication due to KeyEventInterceptor -- NB: popup has focus within root window, it is closed on loss of focus;
wenzelm
parents:
53226
diff
changeset
|
406 |
} |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53183
diff
changeset
|
407 |
|
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53183
diff
changeset
|
408 |
def key_listener( |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53183
diff
changeset
|
409 |
key_typed: KeyEvent => Unit = _ => (), |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53183
diff
changeset
|
410 |
key_pressed: KeyEvent => Unit = _ => (), |
75393 | 411 |
key_released: KeyEvent => Unit = _ => () |
412 |
): KeyListener = { |
|
413 |
def process_key_event(evt0: KeyEvent, handle: KeyEvent => Unit): Unit = { |
|
53237 | 414 |
val evt = KeyEventWorkaround.processKeyEvent(evt0) |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53183
diff
changeset
|
415 |
if (evt != null) handle(evt) |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53183
diff
changeset
|
416 |
} |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53183
diff
changeset
|
417 |
|
75393 | 418 |
new KeyListener { |
73340 | 419 |
def keyTyped(evt: KeyEvent): Unit = process_key_event(evt, key_typed) |
420 |
def keyPressed(evt: KeyEvent): Unit = process_key_event(evt, key_pressed) |
|
421 |
def keyReleased(evt: KeyEvent): Unit = process_key_event(evt, key_released) |
|
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53183
diff
changeset
|
422 |
} |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53183
diff
changeset
|
423 |
} |
53784 | 424 |
|
75393 | 425 |
def special_key(evt: KeyEvent): Boolean = { |
59571 | 426 |
// cf. 5.2.0/jEdit/org/gjt/sp/jedit/gui/KeyEventWorkaround.java |
71500 | 427 |
val mod = evt.getModifiersEx |
428 |
(mod & InputEvent.CTRL_DOWN_MASK) != 0 && (mod & InputEvent.ALT_DOWN_MASK) == 0 || |
|
429 |
(mod & InputEvent.CTRL_DOWN_MASK) == 0 && (mod & InputEvent.ALT_DOWN_MASK) != 0 && |
|
53784 | 430 |
!Debug.ALT_KEY_PRESSED_DISABLED || |
71500 | 431 |
(mod & InputEvent.META_DOWN_MASK) != 0 |
53784 | 432 |
} |
72899 | 433 |
|
434 |
def command_modifier(evt: InputEvent): Boolean = |
|
435 |
(evt.getModifiersEx & Toolkit.getDefaultToolkit.getMenuShortcutKeyMaskEx) != 0 |
|
436 |
||
437 |
def shift_modifier(evt: InputEvent): Boolean = |
|
438 |
(evt.getModifiersEx & InputEvent.SHIFT_DOWN_MASK) != 0 |
|
72927
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72899
diff
changeset
|
439 |
|
81444
cd685e2291fa
clarified mouse selection, avoid conflict of double-click with single-click (follow hyperlink);
wenzelm
parents:
81435
diff
changeset
|
440 |
def alt_modifier(evt: InputEvent): Boolean = |
cd685e2291fa
clarified mouse selection, avoid conflict of double-click with single-click (follow hyperlink);
wenzelm
parents:
81435
diff
changeset
|
441 |
(evt.getModifiersEx & InputEvent.ALT_DOWN_MASK) != 0 |
cd685e2291fa
clarified mouse selection, avoid conflict of double-click with single-click (follow hyperlink);
wenzelm
parents:
81435
diff
changeset
|
442 |
|
72927
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72899
diff
changeset
|
443 |
def modifier_string(evt: InputEvent): String = |
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72899
diff
changeset
|
444 |
KeyEventTranslator.getModifierString(evt) match { |
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72899
diff
changeset
|
445 |
case null => "" |
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72899
diff
changeset
|
446 |
case s => s |
69f768aff611
clarified caret focus modifier, depending on option "jedit_focus_modifier";
wenzelm
parents:
72899
diff
changeset
|
447 |
} |
49406 | 448 |
} |