protected Element[] getSelectedParagraphs() {
		StyledDocument doc = getStyledDocument();
		String t = getSelectedText();
		if (t == null) {
			Element[] e = new Element[1];
			e[0] = doc.getParagraphElement(getCaretPosition());
			return e;
		}
		ArrayList<Element> list = new ArrayList<Element>();
		int start = getSelectionStart();
		int end = getSelectionEnd();
		int length = doc.getLength();
		Element elem = doc.getParagraphElement(start);
		list.add(elem);
		int offset = 0;
		for (int n = 0; n < t.length(); n++) {
			if (t.charAt(n) == '\n') {
				if (n == 0) {
					try {
						if (doc.getText(start - 1 < 0 ? 0 : start - 1, 1).charAt(0) != '\n') {
							elem = doc.getParagraphElement(start + 1);
							list.add(elem);
						}
					} catch (BadLocationException ble) {
						ble.printStackTrace();
					}
				} else if (n == t.length() - 1) {
					try {
						if (doc.getText(end + 1 > length - 1 ? length - 1 : end + 1, 1).charAt(0) != '\n') {
							elem = doc.getParagraphElement(end);
							list.add(elem);
						}
					} catch (BadLocationException ble) {
						ble.printStackTrace();
					}
				} else {
					if (t.charAt(n + 1) != '\n') {
						offset = start + n + 1;
						if (offset < doc.getLength()) {
							elem = doc.getParagraphElement(offset);
							list.add(elem);
						}
					}
				}
			}
		}
		Element[] e = new Element[list.size()];
		for (int i = 0; i < e.length; i++)
			e[i] = list.get(i);
		return e;
	}