src/Tools/jEdit/src/document_view.scala
author wenzelm
Mon Mar 19 23:08:27 2012 +0100 (2012-03-19)
changeset 47027 fc3bb6c02a3c
parent 47013 95bd95addb24
child 47392 6a08fd7a6071
permissions -rw-r--r--
explicit propagation of assignment event, even if changed command set is empty;
discontinued slightly odd Document_View.update_snapshot/flush_snapshot;
wenzelm@43282
     1
/*  Title:      Tools/jEdit/src/document_view.scala
wenzelm@36760
     2
    Author:     Fabian Immler, TU Munich
wenzelm@36760
     3
    Author:     Makarius
wenzelm@36760
     4
wenzelm@36760
     5
Document view connected to jEdit text area.
wenzelm@36760
     6
*/
wenzelm@34408
     7
immler@34403
     8
package isabelle.jedit
immler@34403
     9
wenzelm@34760
    10
wenzelm@36015
    11
import isabelle._
wenzelm@36015
    12
wenzelm@44379
    13
import scala.collection.mutable
wenzelm@45460
    14
import scala.collection.immutable.SortedMap
wenzelm@34784
    15
import scala.actors.Actor._
wenzelm@34784
    16
wenzelm@43520
    17
import java.lang.System
wenzelm@45744
    18
import java.text.BreakIterator
wenzelm@46572
    19
import java.awt.{Color, Graphics2D, Point}
wenzelm@46572
    20
import java.awt.event.{MouseMotionAdapter, MouseEvent,
wenzelm@39741
    21
  FocusAdapter, FocusEvent, WindowEvent, WindowAdapter}
wenzelm@46572
    22
import javax.swing.{Popup, PopupFactory, SwingUtilities, BorderFactory}
wenzelm@34784
    23
import javax.swing.event.{CaretListener, CaretEvent}
wenzelm@34734
    24
wenzelm@43404
    25
import org.gjt.sp.util.Log
wenzelm@43404
    26
wenzelm@42839
    27
import org.gjt.sp.jedit.{jEdit, OperatingSystem, Debug}
wenzelm@34709
    28
import org.gjt.sp.jedit.gui.RolloverButton
wenzelm@39176
    29
import org.gjt.sp.jedit.options.GutterOptionPane
wenzelm@44436
    30
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaExtension, TextAreaPainter,
wenzelm@44436
    31
  ScrollListener}
wenzelm@43369
    32
import org.gjt.sp.jedit.syntax.{SyntaxStyle}
wenzelm@34784
    33
wenzelm@34784
    34
wenzelm@34784
    35
object Document_View
wenzelm@34784
    36
{
wenzelm@34784
    37
  /* document view of text area */
wenzelm@34784
    38
wenzelm@34784
    39
  private val key = new Object
wenzelm@34784
    40
wenzelm@39741
    41
  def apply(text_area: JEditTextArea): Option[Document_View] =
wenzelm@34784
    42
  {
wenzelm@38223
    43
    Swing_Thread.require()
wenzelm@34784
    44
    text_area.getClientProperty(key) match {
wenzelm@34784
    45
      case doc_view: Document_View => Some(doc_view)
wenzelm@34784
    46
      case _ => None
wenzelm@34784
    47
    }
wenzelm@34784
    48
  }
wenzelm@34784
    49
wenzelm@39741
    50
  def exit(text_area: JEditTextArea)
wenzelm@34784
    51
  {
wenzelm@38223
    52
    Swing_Thread.require()
wenzelm@34788
    53
    apply(text_area) match {
wenzelm@39636
    54
      case None =>
wenzelm@34784
    55
      case Some(doc_view) =>
wenzelm@34784
    56
        doc_view.deactivate()
wenzelm@34784
    57
        text_area.putClientProperty(key, null)
wenzelm@34784
    58
    }
wenzelm@34784
    59
  }
wenzelm@43397
    60
wenzelm@43397
    61
  def init(model: Document_Model, text_area: JEditTextArea): Document_View =
wenzelm@43397
    62
  {
wenzelm@43397
    63
    exit(text_area)
wenzelm@43397
    64
    val doc_view = new Document_View(model, text_area)
wenzelm@43397
    65
    text_area.putClientProperty(key, doc_view)
wenzelm@43397
    66
    doc_view.activate()
wenzelm@43397
    67
    doc_view
wenzelm@43397
    68
  }
wenzelm@34784
    69
}
immler@34403
    70
wenzelm@34733
    71
wenzelm@43376
    72
class Document_View(val model: Document_Model, val text_area: JEditTextArea)
immler@34654
    73
{
wenzelm@34784
    74
  private val session = model.session
wenzelm@34784
    75
immler@34403
    76
wenzelm@43419
    77
  /* robust extension body */
wenzelm@43404
    78
wenzelm@43404
    79
  def robust_body[A](default: A)(body: => A): A =
wenzelm@43417
    80
  {
wenzelm@43417
    81
    try {
wenzelm@43417
    82
      Swing_Thread.require()
wenzelm@43417
    83
      if (model.buffer == text_area.getBuffer) body
wenzelm@43417
    84
      else {
wenzelm@43650
    85
        Log.log(Log.ERROR, this, ERROR("Inconsistent document model"))
wenzelm@43417
    86
        default
wenzelm@43404
    87
      }
wenzelm@43404
    88
    }
wenzelm@43417
    89
    catch { case t: Throwable => Log.log(Log.ERROR, this, t); default }
wenzelm@43417
    90
  }
wenzelm@43404
    91
wenzelm@43404
    92
wenzelm@44378
    93
  /* visible text range */
wenzelm@38881
    94
wenzelm@46815
    95
  // NB: TextArea.getScreenLineEndOffset of last line is beyond Buffer.getLength
wenzelm@38881
    96
  def proper_line_range(start: Text.Offset, end: Text.Offset): Text.Range =
wenzelm@46812
    97
    Text.Range(start, end min model.buffer.getLength)
wenzelm@38881
    98
wenzelm@46583
    99
  def visible_range(): Option[Text.Range] =
wenzelm@38881
   100
  {
wenzelm@46583
   101
    val n = text_area.getVisibleLines
wenzelm@46583
   102
    if (n > 0) {
wenzelm@46583
   103
      val start = text_area.getScreenLineStartOffset(0)
wenzelm@46583
   104
      val raw_end = text_area.getScreenLineEndOffset(n - 1)
wenzelm@46583
   105
      Some(proper_line_range(start, if (raw_end >= 0) raw_end else model.buffer.getLength))
wenzelm@46583
   106
    }
wenzelm@46583
   107
    else None
wenzelm@38881
   108
  }
wenzelm@38881
   109
wenzelm@44378
   110
  def invalidate_range(range: Text.Range)
wenzelm@39132
   111
  {
wenzelm@39132
   112
    text_area.invalidateLineRange(
wenzelm@39132
   113
      model.buffer.getLineOfOffset(range.start),
wenzelm@39132
   114
      model.buffer.getLineOfOffset(range.stop))
wenzelm@39132
   115
  }
wenzelm@39132
   116
wenzelm@38881
   117
wenzelm@44379
   118
  /* perspective */
wenzelm@44379
   119
wenzelm@44379
   120
  def perspective(): Text.Perspective =
wenzelm@44379
   121
  {
wenzelm@44379
   122
    Swing_Thread.require()
wenzelm@44776
   123
    val buffer_range = model.buffer_range()
wenzelm@44473
   124
    Text.Perspective(
wenzelm@44379
   125
      for {
wenzelm@44379
   126
        i <- 0 until text_area.getVisibleLines
wenzelm@46997
   127
        start = text_area.getScreenLineStartOffset(i)
wenzelm@46997
   128
        stop = text_area.getScreenLineEndOffset(i)
wenzelm@44379
   129
        if start >= 0 && stop >= 0
wenzelm@46997
   130
        range <- buffer_range.try_restrict(Text.Range(start, stop))
wenzelm@44583
   131
        if !range.is_singularity
wenzelm@44379
   132
      }
wenzelm@44583
   133
      yield range)
wenzelm@44379
   134
  }
wenzelm@44379
   135
wenzelm@44437
   136
  private def update_perspective = new TextAreaExtension
wenzelm@44437
   137
  {
wenzelm@44437
   138
    override def paintScreenLineRange(gfx: Graphics2D,
wenzelm@44437
   139
      first_line: Int, last_line: Int, physical_lines: Array[Int],
wenzelm@44437
   140
      start: Array[Int], end: Array[Int], y: Int, line_height: Int)
wenzelm@44437
   141
    {
wenzelm@44437
   142
      model.update_perspective()
wenzelm@44437
   143
    }
wenzelm@44437
   144
  }
wenzelm@44437
   145
wenzelm@44379
   146
wenzelm@39740
   147
  /* HTML popups */
wenzelm@39740
   148
wenzelm@39740
   149
  private var html_popup: Option[Popup] = None
wenzelm@34834
   150
wenzelm@39740
   151
  private def exit_popup() { html_popup.map(_.hide) }
wenzelm@38881
   152
wenzelm@39740
   153
  private val html_panel =
wenzelm@43661
   154
    new HTML_Panel(Isabelle.font_family(), scala.math.round(Isabelle.font_size()))
wenzelm@39741
   155
  html_panel.setBorder(BorderFactory.createLineBorder(Color.black))
wenzelm@38884
   156
wenzelm@39740
   157
  private def html_panel_resize()
wenzelm@39740
   158
  {
wenzelm@39740
   159
    Swing_Thread.now {
wenzelm@39740
   160
      html_panel.resize(Isabelle.font_family(), scala.math.round(Isabelle.font_size()))
wenzelm@39740
   161
    }
wenzelm@39740
   162
  }
wenzelm@38884
   163
wenzelm@39740
   164
  private def init_popup(snapshot: Document.Snapshot, x: Int, y: Int)
wenzelm@39740
   165
  {
wenzelm@39740
   166
    exit_popup()
wenzelm@40154
   167
/* FIXME broken
wenzelm@39740
   168
    val offset = text_area.xyToOffset(x, y)
wenzelm@39740
   169
    val p = new Point(x, y); SwingUtilities.convertPointToScreen(p, text_area.getPainter)
wenzelm@34784
   170
wenzelm@39740
   171
    // FIXME snapshot.cumulate
wenzelm@45665
   172
    snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Rendering.popup) match {
wenzelm@39740
   173
      case Text.Info(_, Some(msg)) #:: _ =>
wenzelm@39740
   174
        val popup = PopupFactory.getSharedInstance().getPopup(text_area, html_panel, p.x, p.y + 60)
wenzelm@39740
   175
        html_panel.render_sync(List(msg))
wenzelm@39742
   176
        Thread.sleep(10)  // FIXME !?
wenzelm@39740
   177
        popup.show
wenzelm@39740
   178
        html_popup = Some(popup)
wenzelm@39740
   179
      case _ =>
immler@34403
   180
    }
wenzelm@40154
   181
*/
immler@34678
   182
  }
immler@34403
   183
immler@34403
   184
wenzelm@39131
   185
  /* subexpression highlighting */
wenzelm@39131
   186
wenzelm@46205
   187
  @volatile private var _highlight_range: Option[Text.Info[Color]] = None
wenzelm@46205
   188
  def highlight_range(): Option[Text.Info[Color]] = _highlight_range
wenzelm@39740
   189
wenzelm@40338
   190
  private var control: Boolean = false
wenzelm@40338
   191
wenzelm@39740
   192
  private def exit_control()
wenzelm@39740
   193
  {
wenzelm@39740
   194
    exit_popup()
wenzelm@43381
   195
    _highlight_range = None
wenzelm@39740
   196
  }
wenzelm@39740
   197
wenzelm@39131
   198
  private val focus_listener = new FocusAdapter {
wenzelm@39742
   199
    override def focusLost(e: FocusEvent) {
wenzelm@43381
   200
      _highlight_range = None // FIXME exit_control !?
wenzelm@39742
   201
    }
wenzelm@39131
   202
  }
wenzelm@39131
   203
wenzelm@39741
   204
  private val window_listener = new WindowAdapter {
wenzelm@39741
   205
    override def windowIconified(e: WindowEvent) { exit_control() }
wenzelm@39742
   206
    override def windowDeactivated(e: WindowEvent) { exit_control() }
wenzelm@39741
   207
  }
wenzelm@39741
   208
wenzelm@39131
   209
  private val mouse_motion_listener = new MouseMotionAdapter {
wenzelm@39131
   210
    override def mouseMoved(e: MouseEvent) {
wenzelm@46920
   211
      Swing_Thread.assert()
wenzelm@46920
   212
wenzelm@40338
   213
      control = if (OperatingSystem.isMacOS()) e.isMetaDown else e.isControlDown
wenzelm@39740
   214
      val x = e.getX()
wenzelm@39740
   215
      val y = e.getY()
wenzelm@39740
   216
wenzelm@39740
   217
      if (!model.buffer.isLoaded) exit_control()
wenzelm@39132
   218
      else
wenzelm@46920
   219
        Isabelle.buffer_lock(model.buffer) {
wenzelm@47027
   220
          val snapshot = model.snapshot()
wenzelm@39740
   221
wenzelm@39740
   222
          if (control) init_popup(snapshot, x, y)
wenzelm@39740
   223
wenzelm@46205
   224
          for (Text.Info(range, _) <- _highlight_range) invalidate_range(range)
wenzelm@46205
   225
          _highlight_range =
wenzelm@46205
   226
            if (control) {
wenzelm@46205
   227
              val offset = text_area.xyToOffset(x, y)
wenzelm@46205
   228
              Isabelle_Rendering.subexp(snapshot, Text.Range(offset, offset + 1))
wenzelm@46205
   229
            }
wenzelm@46205
   230
            else None
wenzelm@46205
   231
          for (Text.Info(range, _) <- _highlight_range) invalidate_range(range)
wenzelm@39132
   232
        }
wenzelm@39131
   233
    }
wenzelm@39131
   234
  }
wenzelm@39131
   235
wenzelm@39131
   236
wenzelm@43381
   237
  /* text area painting */
wenzelm@39044
   238
wenzelm@43381
   239
  private val text_area_painter = new Text_Area_Painter(this)
wenzelm@39700
   240
wenzelm@43381
   241
  private val tooltip_painter = new TextAreaExtension
wenzelm@43381
   242
  {
wenzelm@34784
   243
    override def getToolTipText(x: Int, y: Int): String =
wenzelm@34784
   244
    {
wenzelm@43404
   245
      robust_body(null: String) {
wenzelm@47027
   246
        val snapshot = model.snapshot()
wenzelm@38845
   247
        val offset = text_area.xyToOffset(x, y)
wenzelm@45460
   248
        val range = Text.Range(offset, offset + 1)
wenzelm@46178
   249
        val tip =
wenzelm@46178
   250
          if (control) Isabelle_Rendering.tooltip(snapshot, range)
wenzelm@46178
   251
          else Isabelle_Rendering.tooltip_message(snapshot, range)
wenzelm@46178
   252
        tip.map(Isabelle.tooltip(_)) getOrElse null
wenzelm@34784
   253
      }
wenzelm@34734
   254
    }
immler@34678
   255
  }
immler@34513
   256
wenzelm@42825
   257
  private val gutter_painter = new TextAreaExtension
wenzelm@39175
   258
  {
wenzelm@39175
   259
    override def paintScreenLineRange(gfx: Graphics2D,
wenzelm@39175
   260
      first_line: Int, last_line: Int, physical_lines: Array[Int],
wenzelm@39175
   261
      start: Array[Int], end: Array[Int], y: Int, line_height: Int)
wenzelm@39175
   262
    {
wenzelm@43404
   263
      robust_body(()) {
wenzelm@46920
   264
        Swing_Thread.assert()
wenzelm@46920
   265
wenzelm@43404
   266
        val gutter = text_area.getGutter
wenzelm@43404
   267
        val width = GutterOptionPane.getSelectionAreaWidth
wenzelm@43404
   268
        val border_width = jEdit.getIntegerProperty("view.gutter.borderWidth", 3)
wenzelm@43404
   269
        val FOLD_MARKER_SIZE = 12
wenzelm@43419
   270
wenzelm@43404
   271
        if (gutter.isSelectionAreaEnabled && !gutter.isExpanded && width >= 12 && line_height >= 12) {
wenzelm@46920
   272
          Isabelle.buffer_lock(model.buffer) {
wenzelm@47027
   273
            val snapshot = model.snapshot()
wenzelm@43404
   274
            for (i <- 0 until physical_lines.length) {
wenzelm@43404
   275
              if (physical_lines(i) != -1) {
wenzelm@43404
   276
                val line_range = proper_line_range(start(i), end(i))
wenzelm@43419
   277
wenzelm@43404
   278
                // gutter icons
wenzelm@46178
   279
                Isabelle_Rendering.gutter_message(snapshot, line_range) match {
wenzelm@46178
   280
                  case Some(icon) =>
wenzelm@46227
   281
                    val x0 = (FOLD_MARKER_SIZE + width - border_width - icon.getIconWidth) max 10
wenzelm@46227
   282
                    val y0 = y + i * line_height + (((line_height - icon.getIconHeight) / 2) max 0)
wenzelm@46227
   283
                    icon.paintIcon(gutter, gfx, x0, y0)
wenzelm@46178
   284
                  case None =>
wenzelm@43404
   285
                }
wenzelm@39175
   286
              }
wenzelm@39175
   287
            }
wenzelm@39175
   288
          }
wenzelm@39175
   289
        }
wenzelm@39175
   290
      }
wenzelm@39175
   291
    }
wenzelm@39175
   292
  }
wenzelm@39175
   293
wenzelm@39175
   294
wenzelm@43448
   295
  /* caret range */
wenzelm@43448
   296
wenzelm@43448
   297
  def caret_range(): Text.Range =
wenzelm@46229
   298
    Isabelle.buffer_lock(model.buffer) {
wenzelm@46229
   299
      def text(i: Text.Offset): Char = model.buffer.getText(i, 1).charAt(0)
wenzelm@46229
   300
      val caret = text_area.getCaretPosition
wenzelm@46229
   301
      try {
wenzelm@46229
   302
        val c = text(caret)
wenzelm@46229
   303
        if (Character.isHighSurrogate(c) && Character.isLowSurrogate(text(caret + 1)))
wenzelm@46229
   304
          Text.Range(caret, caret + 2)
wenzelm@46229
   305
        else if (Character.isLowSurrogate(c) && Character.isHighSurrogate(text(caret - 1)))
wenzelm@46229
   306
          Text.Range(caret - 1, caret + 1)
wenzelm@46229
   307
        else Text.Range(caret, caret + 1)
wenzelm@46229
   308
      }
wenzelm@46229
   309
      catch { case _: ArrayIndexOutOfBoundsException => Text.Range(caret, caret + 1) }
wenzelm@43448
   310
    }
wenzelm@43448
   311
wenzelm@43448
   312
wenzelm@37129
   313
  /* caret handling */
wenzelm@34810
   314
wenzelm@37849
   315
  def selected_command(): Option[Command] =
wenzelm@38223
   316
  {
wenzelm@38223
   317
    Swing_Thread.require()
wenzelm@47027
   318
    model.snapshot().node.command_at(text_area.getCaretPosition).map(_._1)
wenzelm@38223
   319
  }
wenzelm@34810
   320
wenzelm@46740
   321
  private val delay_caret_update =
wenzelm@46740
   322
    Swing_Thread.delay_last(session.input_delay) {
wenzelm@44805
   323
      session.caret_focus.event(Session.Caret_Focus)
wenzelm@34810
   324
    }
wenzelm@46740
   325
wenzelm@46740
   326
  private val caret_listener = new CaretListener {
wenzelm@46740
   327
    override def caretUpdate(e: CaretEvent) { delay_caret_update(true) }
wenzelm@34810
   328
  }
wenzelm@34810
   329
wenzelm@34810
   330
wenzelm@46572
   331
  /* text status overview left of scrollbar */
wenzelm@34784
   332
wenzelm@46572
   333
  private val overview = new Text_Overview(this)
wenzelm@46572
   334
  {
wenzelm@46571
   335
    val delay_repaint =
wenzelm@46571
   336
      Swing_Thread.delay_first(Isabelle.session.update_delay) { repaint() }
wenzelm@34784
   337
  }
immler@34403
   338
wenzelm@34784
   339
wenzelm@39740
   340
  /* main actor */
wenzelm@39740
   341
wenzelm@39740
   342
  private val main_actor = actor {
wenzelm@39740
   343
    loop {
wenzelm@39740
   344
      react {
wenzelm@44608
   345
        case changed: Session.Commands_Changed =>
wenzelm@39740
   346
          val buffer = model.buffer
wenzelm@46918
   347
          Swing_Thread.later {
wenzelm@46918
   348
            Isabelle.buffer_lock(buffer) {
wenzelm@46918
   349
              if (model.buffer == text_area.getBuffer) {
wenzelm@47027
   350
                val snapshot = model.snapshot()
wenzelm@39740
   351
wenzelm@47027
   352
                if (changed.assignment ||
wenzelm@46918
   353
                    (changed.nodes.contains(model.name) &&
wenzelm@46918
   354
                     changed.commands.exists(snapshot.node.commands.contains)))
wenzelm@46918
   355
                  overview.delay_repaint(true)
wenzelm@39740
   356
wenzelm@46918
   357
                visible_range() match {
wenzelm@46918
   358
                  case Some(visible) =>
wenzelm@47027
   359
                    if (changed.assignment) invalidate_range(visible)
wenzelm@46918
   360
                    else {
wenzelm@46918
   361
                      val visible_cmds =
wenzelm@46918
   362
                        snapshot.node.command_range(snapshot.revert(visible)).map(_._1)
wenzelm@46918
   363
                      if (visible_cmds.exists(changed.commands)) {
wenzelm@46918
   364
                        for {
wenzelm@46918
   365
                          line <- 0 until text_area.getVisibleLines
wenzelm@46997
   366
                          start = text_area.getScreenLineStartOffset(line) if start >= 0
wenzelm@46997
   367
                          end = text_area.getScreenLineEndOffset(line) if end >= 0
wenzelm@46997
   368
                          range = proper_line_range(start, end)
wenzelm@46997
   369
                          line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1)
wenzelm@46918
   370
                          if line_cmds.exists(changed.commands)
wenzelm@46918
   371
                        } text_area.invalidateScreenLineRange(line, line)
wenzelm@46918
   372
                      }
wenzelm@46918
   373
                    }
wenzelm@46918
   374
                  case None =>
wenzelm@46583
   375
                }
wenzelm@46918
   376
              }
wenzelm@39740
   377
            }
wenzelm@39740
   378
          }
wenzelm@39740
   379
wenzelm@39740
   380
        case Session.Global_Settings => html_panel_resize()
wenzelm@39740
   381
wenzelm@39740
   382
        case bad => System.err.println("command_change_actor: ignoring bad message " + bad)
wenzelm@39740
   383
      }
wenzelm@39740
   384
    }
wenzelm@39740
   385
  }
wenzelm@39740
   386
wenzelm@39740
   387
wenzelm@34784
   388
  /* activation */
wenzelm@34784
   389
wenzelm@34808
   390
  private def activate()
wenzelm@34784
   391
  {
wenzelm@42825
   392
    val painter = text_area.getPainter
wenzelm@44437
   393
    painter.addExtension(TextAreaPainter.LOWEST_LAYER, update_perspective)
wenzelm@43387
   394
    painter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, tooltip_painter)
wenzelm@43381
   395
    text_area_painter.activate()
wenzelm@42825
   396
    text_area.getGutter.addExtension(gutter_painter)
wenzelm@39131
   397
    text_area.addFocusListener(focus_listener)
wenzelm@39741
   398
    text_area.getView.addWindowListener(window_listener)
wenzelm@42825
   399
    painter.addMouseMotionListener(mouse_motion_listener)
wenzelm@34810
   400
    text_area.addCaretListener(caret_listener)
wenzelm@34810
   401
    text_area.addLeftOfScrollBar(overview)
wenzelm@39740
   402
    session.commands_changed += main_actor
wenzelm@39740
   403
    session.global_settings += main_actor
wenzelm@34784
   404
  }
wenzelm@34784
   405
wenzelm@34808
   406
  private def deactivate()
wenzelm@34784
   407
  {
wenzelm@42825
   408
    val painter = text_area.getPainter
wenzelm@39740
   409
    session.commands_changed -= main_actor
wenzelm@39740
   410
    session.global_settings -= main_actor
wenzelm@39131
   411
    text_area.removeFocusListener(focus_listener)
wenzelm@39741
   412
    text_area.getView.removeWindowListener(window_listener)
wenzelm@42825
   413
    painter.removeMouseMotionListener(mouse_motion_listener)
wenzelm@46740
   414
    text_area.removeCaretListener(caret_listener); delay_caret_update(false)
wenzelm@46740
   415
    text_area.removeLeftOfScrollBar(overview); overview.delay_repaint(false)
wenzelm@42825
   416
    text_area.getGutter.removeExtension(gutter_painter)
wenzelm@43381
   417
    text_area_painter.deactivate()
wenzelm@43381
   418
    painter.removeExtension(tooltip_painter)
wenzelm@44437
   419
    painter.removeExtension(update_perspective)
wenzelm@39740
   420
    exit_popup()
wenzelm@34784
   421
  }
wenzelm@42825
   422
}