wp/wp-admin/js/editor.js
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
--- a/wp/wp-admin/js/editor.js	Fri Sep 05 18:40:08 2025 +0200
+++ b/wp/wp-admin/js/editor.js	Fri Sep 05 18:52:52 2025 +0200
@@ -22,7 +22,7 @@
 				$$ = tinymce.$;
 
 				/**
-				 * Handles onclick events for the Visual/Text tabs.
+				 * Handles onclick events for the Visual/Code tabs.
 				 *
 				 * @since 4.3.0
 				 *
@@ -62,7 +62,7 @@
 		}
 
 		/**
-		 * Switches the editor between Visual and Text mode.
+		 * Switches the editor between Visual and Code mode.
 		 *
 		 * @since 2.5.0
 		 *
@@ -79,6 +79,8 @@
 			var editorHeight, toolbarHeight, iframe,
 				editor = tinymce.get( id ),
 				wrap = $$( '#wp-' + id + '-wrap' ),
+				htmlSwitch = wrap.find( '.switch-tmce' ),
+				tmceSwitch = wrap.find( '.switch-html' ),
 				$textarea = $$( '#' + id ),
 				textarea = $textarea[0];
 
@@ -103,18 +105,7 @@
 
 				editorHeight = parseInt( textarea.style.height, 10 ) || 0;
 
-				var keepSelection = false;
-				if ( editor ) {
-					keepSelection = editor.getParam( 'wp_keep_scroll_position' );
-				} else {
-					keepSelection = window.tinyMCEPreInit.mceInit[ id ] &&
-									window.tinyMCEPreInit.mceInit[ id ].wp_keep_scroll_position;
-				}
-
-				if ( keepSelection ) {
-					// Save the selection.
-					addHTMLBookmarkInTextAreaContent( $textarea );
-				}
+				addHTMLBookmarkInTextAreaContent( $textarea );
 
 				if ( editor ) {
 					editor.show();
@@ -130,15 +121,14 @@
 						}
 					}
 
-					if ( editor.getParam( 'wp_keep_scroll_position' ) ) {
-						// Restore the selection.
-						focusHTMLBookmarkInVisualEditor( editor );
-					}
+					focusHTMLBookmarkInVisualEditor( editor );
 				} else {
 					tinymce.init( window.tinyMCEPreInit.mceInit[ id ] );
 				}
 
 				wrap.removeClass( 'html-active' ).addClass( 'tmce-active' );
+				tmceSwitch.attr( 'aria-pressed', false );
+				htmlSwitch.attr( 'aria-pressed', true );
 				$textarea.attr( 'aria-hidden', true );
 				window.setUserSetting( 'editor', 'tinymce' );
 
@@ -168,9 +158,7 @@
 
 					var selectionRange = null;
 
-					if ( editor.getParam( 'wp_keep_scroll_position' ) ) {
-						selectionRange = findBookmarkedPosition( editor );
-					}
+					selectionRange = findBookmarkedPosition( editor );
 
 					editor.hide();
 
@@ -184,6 +172,8 @@
 				}
 
 				wrap.removeClass( 'tmce-active' ).addClass( 'html-active' );
+				tmceSwitch.attr( 'aria-pressed', true );
+				htmlSwitch.attr( 'aria-pressed', false );
 				$textarea.attr( 'aria-hidden', false );
 				window.setUserSetting( 'editor', 'html' );
 			}
@@ -520,7 +510,7 @@
 		 * Focuses the selection markers in Visual mode.
 		 *
 		 * The method checks for existing selection markers inside the editor DOM (Visual mode)
-		 * and create a selection between the two nodes using the DOM `createRange` selection API
+		 * and create a selection between the two nodes using the DOM `createRange` selection API.
 		 *
 		 * If there is only a single node, select only the single node through TinyMCE's selection API
 		 *
@@ -545,9 +535,7 @@
 				}
 			}
 
-			if ( editor.getParam( 'wp_keep_scroll_position' ) ) {
-				scrollVisualModeToStartElement( editor, startNode );
-			}
+			scrollVisualModeToStartElement( editor, startNode );
 
 			removeSelectionMarker( startNode );
 			removeSelectionMarker( endNode );
@@ -850,7 +838,7 @@
 			}
 		}
 
-		// Restore the selection when the editor is initialized. Needed when the Text editor is the default.
+		// Restore the selection when the editor is initialized. Needed when the Code editor is the default.
 		$( document ).on( 'tinymce-editor-init.keep-scroll-position', function( event, editor ) {
 			if ( editor.$( '.mce_SELRES_start' ).length ) {
 				focusHTMLBookmarkInVisualEditor( editor );
@@ -1215,7 +1203,7 @@
 	/**
 	 * Initialize TinyMCE and/or Quicktags. For use with wp_enqueue_editor() (PHP).
 	 *
-	 * Intended for use with an existing textarea that will become the Text editor tab.
+	 * Intended for use with an existing textarea that will become the Code editor tab.
 	 * The editor width will be the width of the textarea container, height will be adjustable.
 	 *
 	 * Settings for both TinyMCE and Quicktags can be passed on initialization, and are "filtered"
@@ -1258,7 +1246,7 @@
 			};
 		}
 
-		// Add wrap and the Visual|Text tabs.
+		// Add wrap and the Visual|Code tabs.
 		if ( settings.tinymce && settings.quicktags ) {
 			var $textarea = $( '#' + id );
 
@@ -1305,7 +1293,7 @@
 						.append( $button.attr({
 							id: id + '-html',
 							'class': 'wp-switch-editor switch-html'
-						}).text( window.tinymce.translate( 'Text' ) ) )
+						}).text( window.tinymce.translate( 'Code|tab' ) ) )
 					).append( $editorContainer )
 			);