Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -692,16 +692,17 @@ private void broadcastParagraphs(Map<String, Paragraph> userParagraphMap, Paragr
inlineBroadcastParagraphs(userParagraphMap, msgId);
}

private void inlineBroadcastNewParagraph(Note note, Paragraph para) {
private void inlineBroadcastNewParagraph(Note note, Paragraph para, String msgId) {
LOGGER.info("Broadcasting paragraph on run call instead of note.");
int paraIndex = note.getParagraphs().indexOf(para);

Message message = new Message(OP.PARAGRAPH_ADDED).put("paragraph", para).put("index", paraIndex);
Message message =
new Message(OP.PARAGRAPH_ADDED).withMsgId(msgId).put("paragraph", para).put("index", paraIndex);
connectionManager.broadcast(note.getId(), message);
}

private void broadcastNewParagraph(Note note, Paragraph para) {
inlineBroadcastNewParagraph(note, para);
private void broadcastNewParagraph(Note note, Paragraph para, String msgId) {
inlineBroadcastNewParagraph(note, para, msgId);
}

private void inlineBroadcastNoteList() {
Expand Down Expand Up @@ -1451,7 +1452,7 @@ private String insertParagraph(NotebookSocket conn,
@Override
public void onSuccess(Paragraph p, ServiceContext context) throws IOException {
super.onSuccess(p, context);
broadcastNewParagraph(p.getNote(), p);
broadcastNewParagraph(p.getNote(), p, fromMessage.msgId);
}
});

Expand Down Expand Up @@ -1555,7 +1556,7 @@ public void onSuccess(Paragraph p, ServiceContext context)
StringUtils.isEmpty(p.getScriptText())) &&
isTheLastParagraph) {
Paragraph newPara = p.getNote().addNewParagraph(p.getAuthenticationInfo());
broadcastNewParagraph(p.getNote(), newPara);
broadcastNewParagraph(p.getNote(), newPara, fromMessage.msgId);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export interface ImportNoteReceived {

export interface ParagraphAdded {
index: number;
msgId?: string;
paragraph: ParagraphItem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ export class NotebookComponent extends MessageListenersManager implements OnInit

definedNote.paragraphs[paragraphIndex].focus = true;
this.cdr.markForCheck();

// Focus the editor only for a clone/insert initiated by this client (not auto-append on run or remote inserts).
// Defer a tick so the new paragraph's editor child exists, since `focus = true` alone misses it.
if (this.messageService.consumeLocalAddFocusMsgId(data.msgId)) {
const addedId = data.paragraph.id;
setTimeout(() => {
const added = this.listOfNotebookParagraphComponent?.find(e => e.paragraph.id === addedId);
added?.focusEditor();
added?.notebookParagraphCodeEditorComponent?.setRestorePosition();
});
}
}

@MessageListener(OP.SAVE_NOTE_FORMS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,24 @@ export class NotebookParagraphCodeEditorComponent
this.position = e.position;
});
}),
editor.onDidChangeModelContent(() => {
editor.onDidChangeModelContent(e => {
this.ngZone.run(() => {
const model = editor.getModel();
if (!model) {
throw new Error('Model content changed but model not found.');
}
this.text = model.getValue();
this.textChanged.emit(this.text);
this.setParagraphMode(true);
this.autoAdjustEditorHeight();
setTimeout(() => {
this.autoAdjustEditorHeight();
});
this.setParagraphMode(true);
// A flush is a programmatic setValue (editor init, remote content update, patch), not a user edit.
// Such changes must not mark the paragraph dirty.
if (e.isFlush) {
return;
}
this.textChanged.emit(this.text);
});
})
);
Expand Down
40 changes: 37 additions & 3 deletions zeppelin-web-angular/src/app/services/message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import { Inject, Injectable, OnDestroy, Optional } from '@angular/core';
import { Observable } from 'rxjs';
import { take } from 'rxjs/operators';

import { MessageInterceptor, MESSAGE_INTERCEPTOR } from '@zeppelin/interfaces';
import {
Expand All @@ -22,6 +23,7 @@ import {
MessageSendDataTypeMap,
Note,
NoteConfig,
OP,
ParagraphConfig,
ParagraphParams,
PersonalizedMode,
Expand All @@ -38,6 +40,8 @@ import { TicketService } from './ticket.service';
providedIn: 'root'
})
export class MessageService extends Message implements OnDestroy {
private readonly localAddFocusMsgIds = new Set<string>();

constructor(
private baseUrlService: BaseUrlService,
private ticketService: TicketService,
Expand All @@ -47,7 +51,11 @@ export class MessageService extends Message implements OnDestroy {
}

interceptReceived(data: WebSocketMessage<MessageReceiveDataTypeMap>): WebSocketMessage<MessageReceiveDataTypeMap> {
return this.messageInterceptor ? this.messageInterceptor.received(data) : super.interceptReceived(data);
const received = this.messageInterceptor ? this.messageInterceptor.received(data) : super.interceptReceived(data);
if (received.op === OP.PARAGRAPH_ADDED && received.data && received.msgId) {
(received.data as MessageReceiveDataTypeMap[OP.PARAGRAPH_ADDED]).msgId = received.msgId;
}
return received;
}

bootstrap(): void {
Expand Down Expand Up @@ -78,6 +86,30 @@ export class MessageService extends Message implements OnDestroy {
return super.receive<K>(op);
}

consumeLocalAddFocusMsgId(msgId: string | undefined): boolean {
if (!msgId) {
return false;
}
return this.localAddFocusMsgIds.delete(msgId);
}

private captureLocalAddFocusMsgId(sendMessage: () => void): void {
const subscription = super
.sent()
.pipe(take(1))
.subscribe(message => {
if (message.msgId) {
this.localAddFocusMsgIds.add(message.msgId);
}
});
try {
sendMessage();
} catch (error) {
subscription.unsubscribe();
throw error;
}
}
Comment thread
tbonelee marked this conversation as resolved.

opened(): Observable<Event> {
return super.opened();
}
Expand Down Expand Up @@ -167,7 +199,7 @@ export class MessageService extends Message implements OnDestroy {
}

insertParagraph(newIndex: number): void {
super.insertParagraph(newIndex);
this.captureLocalAddFocusMsgId(() => super.insertParagraph(newIndex));
}

copyParagraph(
Expand All @@ -177,7 +209,9 @@ export class MessageService extends Message implements OnDestroy {
paragraphConfig: ParagraphConfig,
paragraphParams: ParagraphParams
): void {
super.copyParagraph(newIndex, paragraphTitle, paragraphData, paragraphConfig, paragraphParams);
this.captureLocalAddFocusMsgId(() =>
super.copyParagraph(newIndex, paragraphTitle, paragraphData, paragraphConfig, paragraphParams)
);
}

angularObjectUpdate(
Expand Down
Loading