File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1030,10 +1030,18 @@ def dispose(self) -> None:
10301030 def tab_label (self ) -> str :
10311031 """Short name for the tab bar (with dirty star).
10321032
1033+ For a file-backed tab the title is the filename; otherwise it is the
1034+ first line of the document, truncated to 15 characters (``Untitled``
1035+ when the document is empty).
1036+
10331037 Returns:
1034- Filename or ``Untitled`` , prefixed with ``*`` when dirty.
1038+ Filename or first-line snippet , prefixed with ``*`` when dirty.
10351039 """
1036- name = self .path .name if self .path is not None else "Untitled"
1040+ if self .path is not None :
1041+ name = self .path .name
1042+ else :
1043+ first = self .editor .toPlainText ().splitlines ()
1044+ name = first [0 ].strip ()[:15 ] if first and first [0 ].strip () else "Untitled"
10371045 if self .locked :
10381046 name = f"{ name } (locked)"
10391047 return f"*{ name } " if self .dirty else name
@@ -1089,6 +1097,9 @@ def _on_text_changed(self) -> None:
10891097 if not self .dirty :
10901098 self .dirty = True
10911099 self .meta_changed .emit ()
1100+ elif self .path is None and not self .locked :
1101+ # Untitled tab: title reflects the first line, so refresh live.
1102+ self .meta_changed .emit ()
10921103 if self ._sync_preview_from_source :
10931104 self ._preview_timer .start ()
10941105
You can’t perform that action at this time.
0 commit comments