void (@NotNull DocumentEvent e) { if (!ApplicationManager.getApplication().isDispatchThread()) { return;// Changes in lightweight documents are irrelevant to bookmarks and have to be ignored } VirtualFile file = FileDocumentManager.getInstance().getFile(e.getDocument()); List<Bookmark> bookmarksToRemove = null; if (file != null) { for (Bookmark bookmark : myBookmarks.get(file)) { if (!bookmark.isValid() || isDuplicate(bookmark, file, bookmarksToRemove)) { if (bookmarksToRemove == null) { bookmarksToRemove = new ArrayList<>(); } bookmarksToRemove.add(bookmark); } } } if (bookmarksToRemove != null) { for (Bookmark bookmark : bookmarksToRemove) { moveToDeleted(bookmark); } } myBeforeChangeData.remove(e.getDocument()); for (Iterator<Map.Entry<DeletedDocumentBookmarkKey, Bookmark>> iterator = myDeletedDocumentBookmarks.entrySet().iterator(); iterator.hasNext(); ) { Map.Entry<DeletedDocumentBookmarkKey, Bookmark> entry = iterator.next(); VirtualFile virtualFile = entry.getKey().file; if (!virtualFile.isValid()) { iterator.remove(); continue; } Bookmark bookmark = entry.getValue(); Document document = bookmark.getCachedDocument(); if (document == null || !bookmark.getFile().equals(virtualFile)) { continue; } int line = entry.getKey().line; if (document.getLineCount() <= line) { continue; } String lineContent = getLineContent(document, line); String bookmarkedText = entry.getKey().text; //'move statement up' action kills line bookmark: fix for single line movement up/down if (!bookmarkedText.equals(lineContent) && line > 1 && (bookmarkedText.equals(StringUtil.trimEnd(e.getNewFragment().toString(), "\n")) || bookmarkedText.equals(StringUtil.trimEnd(e.getOldFragment().toString(), "\n")))) { line -= 2; lineContent = getLineContent(document, line); } if (bookmarkedText.equals(lineContent) && findEditorBookmark(document, line) == null) { Bookmark restored = addTextBookmark(bookmark.getFile(), line, bookmark.getDescription()); if (bookmark.getMnemonic() != 0) { setMnemonic(restored, bookmark.getMnemonic()); } iterator.remove(); } } }