# Toggling word wrap [edit]

This Help topic describes how to use a short Eclipse Monkey script to toggle the current editor's text wrapping setting.

## Introduction

Aptana Studio currently does not support word wrapping due to a limitation in the Eclipse framework. However, it is possible to access the text widget responsible for the display of text in the Aptana editors. Gaining access to this widget allows Eclipse Monkey to toggle the word wrap setting. Please note that there are known issues when word wrap is turned on.

## Instructions

1. Create a new, empty Eclipse Monkey script. See Creating a new Eclipse Monkey script for instructions.

   Name the file something related to the actual script that you want to execute (e.g. toggle_word_wrap.js).

2. Copy and paste the JavaScript below into your new file:

       /*
        * Menu: Editors > Toggle Word Wrap
        * Kudos: Kevin Lindsey (Aptana, Inc.)
        * License: EPL 1.0
        * DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
        */

       /**
        * main
        */
       function main()
       {
       	var textWidget = getTextWidget();

       	if (textWidget)
       	{
       		var setting = textWidget.getWordWrap() == false;

       		textWidget.setWordWrap(setting);

       		if (setting)
       		{
       			out.println("Word wrap is on");
       		}
       		else
       		{
       			out.println("Word wrap is off");
       		}
       	}
       }

       /**
        * getTextWidget
        */
       function getTextWidget()
       {
       	var result = null;

       	try
       	{
       		result = editors.activeEditor.textEditor.getViewer().getTextWidget()
       	}
       	catch (e)
       	{
       		// fail silently
       	}

       	return result;
       }

You should now be able to execute this script using the menu item in the sample script (i.e. Scripts > Editors > Toggle Word Wrap), or any other metadata that you added on your own.

## Related Topics

- About Aptana Snippets
- Editing with Snippets
- Adding a new Snippet
- Editing a Snippet
- Scripting with Eclipse Monkey
- Adding metadata to an Eclipse Monkey script
- Assigning a keyboard shortcut to a snippet

Retrieved from "http://aptana.com/docs/index.php/Toggling_word_wrap"

Category: AptanaHelp