frontTag = tag.getName( ).replaceFirst( ">", text + ">" ); }   Point point = textEditor.getSelection( ); int start = point.x < point.y ? point.x : point.y; String selectedText = textEditor.getSelectionText( );  if ( tag.isPair( ) ) { String text; if ( selectedText.length( ) == 0 ) { text = frontTag + textEditor.getLineDelimiter( ) + textEditor.getLineDelimiter( ) + backTag; } else { text = frontTag + selectedText + backTag; } textEditor.insert( text ); } else { textEditor.insert( frontTag + selectedText ); }    if ( !tag.getAttributes( ).isEmpty( ) ) { textEditor.setCaretOffset( start + tag.getName( ).length( ) + ( (String) tag.getAttributes( ).get( 0 ) ).length( ) + 2 ); } else { int offset = start + frontTag.length( ); if ( tag.isPair( ) && selectedText.length( ) == 0 ) {   offset = textEditor.getOffsetAtLine( textEditor.getLineAtOffset( start ) + 1 ); } textEditor.setCaretOffset( offset ); } }
			public void widgetSelected( SelectionEvent e )			{				String frontTag = tag.getName( );				String backTag = tag.getName( ).replaceFirst( "<", "</" ); //$NON-NLS-1$ //$NON-NLS-2$								// if tag.attributes is not empty, then adds its attributes				// following the front tag.				if ( !tag.getAttributes( ).isEmpty( ) )				{					String text = " "; //$NON-NLS-1$					for ( Iterator iter = tag.getAttributes( ).iterator( ); iter.hasNext( ); )					{						text = text + (String) iter.next( ) + "=\"\" "; //$NON-NLS-1$					}					frontTag = tag.getName( ).replaceFirst( ">", text + ">" ); //$NON-NLS-1$ //$NON-NLS-2$									}				// start: the start offset of selected text.				Point point = textEditor.getSelection( );				int start = point.x < point.y ? point.x : point.y;				String selectedText = textEditor.getSelectionText( );				if ( tag.isPair( ) )				{					String text;					if ( selectedText.length( ) == 0 )					{						text = frontTag								+ textEditor.getLineDelimiter( )								+ textEditor.getLineDelimiter( )								+ backTag;					}					else					{						text = frontTag + selectedText + backTag;					}					textEditor.insert( text );				}				else				{					textEditor.insert( frontTag + selectedText );				}				// if the tag takes some attributes, then set the				// cursor to the first attribute.				if ( !tag.getAttributes( ).isEmpty( ) )				{					textEditor.setCaretOffset( start							+ tag.getName( ).length( )							+ ( (String) tag.getAttributes( ).get( 0 ) ).length( )							+ 2 );				}				else				{					int offset = start + frontTag.length( );					if ( tag.isPair( ) && selectedText.length( ) == 0 )					{						// a new line break is needed, set cursor to the new						// line.						offset = textEditor.getOffsetAtLine( textEditor.getLineAtOffset( start ) + 1 );					}					textEditor.setCaretOffset( offset );				}			}