private void addMarker(Marker m, ChatLine chatLine) { String markerId = editor.newItemId(); Doc v = cdoc.getShared().getValue(); // Adding the marker to the selection marker position, a bit of a hack. Marker sema = v.getMarkers().get(user.getSelectionMarkerId()); if (sema == null) { getWindow().showNotification("Something went wrong marker-wise :( Please try again."); return; } String text = v.getText(); int start = sema.getStart(); int end = sema.getEnd(); m = m.withNewPos(start, end); DocDiff d = DocDiff.addMarker(markerId, m, text); cdoc.getShared().applyDiff(d, editor.getCollaboratorId()); if (chatLine != null) { List<ChatLine> lines = Collections.singletonList(chatLine); project.getDoc(file).getMarkerChatCreateIfNotExist(markerId, lines); } latestMarkers.put(markerId, m); activeMarker = markerId; updateMarkers(latestMarkers); showMarkerPopup(); editor.requestRepaint(); }