diff options
| -rw-r--r-- | cocoa/ScintillaCocoa.mm | 15 | ||||
| -rw-r--r-- | doc/ScintillaDoc.html | 4 | ||||
| -rw-r--r-- | gtk/ScintillaGTK.cxx | 12 | ||||
| -rw-r--r-- | qt/ScintillaEditBase/ScintillaQt.cpp | 16 | ||||
| -rw-r--r-- | src/Editor.cxx | 39 | ||||
| -rw-r--r-- | src/Editor.h | 6 | ||||
| -rw-r--r-- | src/Selection.cxx | 8 | ||||
| -rw-r--r-- | src/Selection.h | 1 | ||||
| -rw-r--r-- | win32/ScintillaWin.cxx | 49 | 
9 files changed, 66 insertions, 84 deletions
| diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index cf517db2d..98f5bb054 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -984,16 +984,8 @@ void ScintillaCocoa::Paste(bool forceRectangular)    pdoc->BeginUndoAction();    ClearSelection(false); -  int length = selectedText.Length(); -  SelectionPosition selStart = sel.RangeMain().Start(); -  if (selectedText.rectangular) -  { -    PasteRectangular(selStart, selectedText.Data(), length); -  } -  else -  { -    InsertPaste(selStart, selectedText.Data(), length); -  } +  InsertPasteShape(selectedText.Data(), selectedText.Length(), +	  selectedText.rectangular ? pasteRectangular : pasteStream);    pdoc->EndUndoAction();    Redraw(); @@ -1495,8 +1487,7 @@ bool ScintillaCocoa::GetPasteboardData(NSPasteboard* board, SelectionText* selec        bool rectangular = bestType == ScintillaRecPboardType; -      int len = static_cast<int>(usedLen); -      std::string dest = Document::TransformLineEnds((char *)buffer.data(), len, pdoc->eolMode); +      std::string dest(buffer.data(), usedLen);        selectedText->Copy(dest, pdoc->dbcsCodePage,                           vs.styles[STYLE_DEFAULT].characterSet , rectangular, false); diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index a97aa6858..0f108917a 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -82,7 +82,7 @@      <h1>Scintilla Documentation</h1> -    <p>Last edited 21 April 2014 NH</p> +    <p>Last edited 1 May 2014 NH</p>      <p>There is <a class="jump" href="Design.html">an overview of the internal design of      Scintilla</a>.<br /> @@ -983,7 +983,7 @@ struct Sci_TextToFind {       If this property is set then when text is pasted any line ends are converted to match the document's       end of line mode as set with       <a class="message" href="#SCI_SETEOLMODE">SCI_SETEOLMODE</a>. -     Currently only changeable on Windows. On GTK+ pasted text is always converted.</p> +     Defaults to true.</p>      <h2 id="ErrorHandling">Error handling</h2> diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 236778d93..f13686077 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -1496,7 +1496,7 @@ void ScintillaGTK::GetGtkSelectionText(GtkSelectionData *selectionData, Selectio  		len--;	// Forget the extra '\0'  #endif -	std::string dest = Document::TransformLineEnds(data, len, pdoc->eolMode); +	std::string dest(data, len);  	if (selectionTypeData == GDK_TARGET_STRING) {  		if (IsUnicodeMode()) {  			// Unknown encoding so assume in Latin1 @@ -1537,15 +1537,9 @@ void ScintillaGTK::ReceivedSelection(GtkSelectionData *selection_data) {  				if (SelectionOfGSD(selection_data) != GDK_SELECTION_PRIMARY) {  					ClearSelection(multiPasteMode == SC_MULTIPASTE_EACH);  				} -				SelectionPosition selStart = sel.IsRectangular() ? -					sel.Rectangular().Start() : -					sel.Range(sel.Main()).Start(); -				if (selText.rectangular) { -					PasteRectangular(selStart, selText.Data(), selText.Length()); -				} else { -					InsertPaste(selStart, selText.Data(), selText.Length()); -				} +				InsertPasteShape(selText.Data(), selText.Length(), +					selText.rectangular ? pasteRectangular : pasteStream);  				EnsureCaretVisible();  			}  		} diff --git a/qt/ScintillaEditBase/ScintillaQt.cpp b/qt/ScintillaEditBase/ScintillaQt.cpp index 03218cf34..fae5b730d 100644 --- a/qt/ScintillaEditBase/ScintillaQt.cpp +++ b/qt/ScintillaEditBase/ScintillaQt.cpp @@ -339,21 +339,14 @@ void ScintillaQt::PasteFromMode(QClipboard::Mode clipboardMode_)  	bool isRectangular = IsRectangularInMime(mimeData);  	QString text = clipboard->text(clipboardMode_);  	QByteArray utext = BytesForDocument(text); -	int len = utext.length(); -	std::string dest = Document::TransformLineEnds(utext, len, pdoc->eolMode); +	std::string dest(utext, utext.length());  	SelectionText selText;  	selText.Copy(dest, pdoc->dbcsCodePage, CharacterSetOfDocument(), isRectangular, false);  	UndoGroup ug(pdoc);  	ClearSelection(multiPasteMode == SC_MULTIPASTE_EACH); -	SelectionPosition selStart = sel.IsRectangular() ? -		sel.Rectangular().Start() : -		sel.Range(sel.Main()).Start(); -	if (selText.rectangular) { -		PasteRectangular(selStart, selText.Data(), static_cast<int>(selText.Length())); -	} else { -		InsertPaste(selStart, selText.Data(), static_cast<int>(selText.Length())); -	} +	InsertPasteShape(selText.Data(), static_cast<int>(selText.Length()), +		selText.rectangular ? pasteRectangular : pasteStream);  	EnsureCaretVisible();  } @@ -741,10 +734,9 @@ void ScintillaQt::Drop(const Point &point, const QMimeData *data, bool move)  	bool rectangular = IsRectangularInMime(data);  	QByteArray bytes = BytesForDocument(text);  	int len = bytes.length(); -	std::string dest = Document::TransformLineEnds(bytes, len, pdoc->eolMode);  	SelectionPosition movePos = SPositionFromLocation(point,  				false, false, UserVirtualSpace()); -	DropAt(movePos, dest.c_str(), dest.length(), move, rectangular); +	DropAt(movePos, bytes, len, move, rectangular);  } diff --git a/src/Editor.cxx b/src/Editor.cxx index 2ad5f5863..b690d8011 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -4152,8 +4152,9 @@ void Editor::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) {  	}  } -void Editor::InsertPaste(SelectionPosition selStart, const char *text, int len) { +void Editor::InsertPaste(const char *text, int len) {  	if (multiPasteMode == SC_MULTIPASTE_ONCE) { +		SelectionPosition selStart = sel.Start();  		selStart = SelectionPosition(InsertSpace(selStart.Position(), selStart.VirtualSpace()));  		const int lengthInserted = pdoc->InsertString(selStart.Position(), text, len);  		if (lengthInserted > 0) { @@ -4186,6 +4187,35 @@ void Editor::InsertPaste(SelectionPosition selStart, const char *text, int len)  	}  } +void Editor::InsertPasteShape(const char *text, int len, PasteShape shape) { +	std::string convertedText; +	if (convertPastes) { +		// Convert line endings of the paste into our local line-endings mode +		convertedText = Document::TransformLineEnds(text, len, pdoc->eolMode); +		len = static_cast<int>(convertedText.length()); +		text = convertedText.c_str(); +	} +	if (shape == pasteRectangular) { +		PasteRectangular(sel.Start(), text, len); +	} else { +		if (shape == pasteLine) { +			int insertPos = pdoc->LineStart(pdoc->LineFromPosition(sel.MainCaret())); +			int lengthInserted = pdoc->InsertString(insertPos, text, len); +			// add the newline if necessary +			if ((len > 0) && (text[len - 1] != '\n' && text[len - 1] != '\r')) { +				const char *endline = StringFromEOLMode(pdoc->eolMode); +				int length = static_cast<int>(strlen(endline)); +				lengthInserted += pdoc->InsertString(insertPos + lengthInserted, endline, length); +			} +			if (sel.MainCaret() == insertPos) { +				SetEmptySelection(sel.MainCaret() + lengthInserted); +			} +		} else { +			InsertPaste(text, len); +		} +	} +} +  void Editor::ClearSelection(bool retainMultipleSelections) {  	if (!sel.IsRectangular() && !retainMultipleSelections)  		FilterSelections(); @@ -6150,14 +6180,17 @@ void Editor::DropAt(SelectionPosition position, const char *value, size_t length  		}  		position = positionAfterDeletion; +		std::string convertedText = Document::TransformLineEnds(value, lengthValue, pdoc->eolMode); +  		if (rectangular) { -			PasteRectangular(position, value, static_cast<int>(lengthValue)); +			PasteRectangular(position, convertedText.c_str(), static_cast<int>(convertedText.length()));  			// Should try to select new rectangle but it may not be a rectangle now so just select the drop position  			SetEmptySelection(position);  		} else {  			position = MovePositionOutsideChar(position, sel.MainCaret() - position.Position());  			position = SelectionPosition(InsertSpace(position.Position(), position.VirtualSpace())); -			const int lengthInserted = pdoc->InsertString(position.Position(), value, static_cast<int>(lengthValue)); +			const int lengthInserted = pdoc->InsertString( +				position.Position(), convertedText.c_str(), static_cast<int>(convertedText.length()));  			if (lengthInserted > 0) {  				SelectionPosition posAfterInsertion = position;  				posAfterInsertion.Add(lengthInserted); diff --git a/src/Editor.h b/src/Editor.h index 119d03379..15a0fcf04 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -473,8 +473,10 @@ protected:	// ScintillaBase subclass needs access to much of Editor  	int InsertSpace(int position, unsigned int spaces);  	void AddChar(char ch);  	virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false); -	void InsertPaste(SelectionPosition selStart, const char *text, int len); -	void ClearSelection(bool retainMultipleSelections=false); +	void InsertPaste(const char *text, int len); +	enum PasteShape { pasteStream=0, pasteRectangular = 1, pasteLine = 2 }; +	void InsertPasteShape(const char *text, int len, PasteShape shape); +	void ClearSelection(bool retainMultipleSelections = false);  	void ClearAll();  	void ClearDocumentStyle();  	void Cut(); diff --git a/src/Selection.cxx b/src/Selection.cxx index ae4d8bfc7..4c2ab0508 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -230,6 +230,14 @@ SelectionRange &Selection::RangeMain() {  	return ranges[mainRange];  } +SelectionPosition Selection::Start() const { +	if (IsRectangular()) { +		return rangeRectangular.Start(); +	} else { +		return ranges[mainRange].Start(); +	} +} +  bool Selection::MoveExtends() const {  	return moveExtends;  } diff --git a/src/Selection.h b/src/Selection.h index e84d3c32c..e7f62f061 100644 --- a/src/Selection.h +++ b/src/Selection.h @@ -157,6 +157,7 @@ public:  	void SetMain(size_t r);  	SelectionRange &Range(size_t r);  	SelectionRange &RangeMain(); +	SelectionPosition Start() const;  	bool MoveExtends() const;  	void SetMoveExtends(bool moveExtends_);  	bool Empty() const; diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index a0372f574..e084354f1 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -274,8 +274,6 @@ class ScintillaWin :  	virtual bool GetScrollInfo(int nBar, LPSCROLLINFO lpsi);  	void ChangeScrollPos(int barType, int pos); -	void InsertPasteText(const char *text, int len, SelectionPosition selStart, bool isRectangular, bool isLine); -  public:  	// Public for benefit of Scintilla_DirectFunction  	virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam); @@ -1648,44 +1646,12 @@ public:  	}  }; -void ScintillaWin::InsertPasteText(const char *text, int len, SelectionPosition selStart, bool isRectangular, bool isLine) { -	if (isRectangular) { -		PasteRectangular(selStart, text, len); -	} else { -		std::string convertedText; -		if (convertPastes) { -			// Convert line endings of the paste into our local line-endings mode -			convertedText = Document::TransformLineEnds(text, len, pdoc->eolMode); -			len = static_cast<int>(convertedText.length()); -			text = convertedText.c_str(); -		} -		if (isLine) { -			int insertPos = pdoc->LineStart(pdoc->LineFromPosition(sel.MainCaret())); -			int lengthInserted = pdoc->InsertString(insertPos, text, len); -			// add the newline if necessary -			if ((len > 0) && (text[len-1] != '\n' && text[len-1] != '\r')) { -				const char *endline = StringFromEOLMode(pdoc->eolMode); -				int length = static_cast<int>(strlen(endline)); -				lengthInserted += pdoc->InsertString(insertPos + lengthInserted, endline, length); -			} -			if (sel.MainCaret() == insertPos) { -				SetEmptySelection(sel.MainCaret() + lengthInserted); -			} -		} else { -			InsertPaste(selStart, text, len); -		} -	} -} -  void ScintillaWin::Paste() {  	if (!::OpenClipboard(MainHWND()))  		return;  	UndoGroup ug(pdoc); -	bool isLine = SelectionEmpty() && (::IsClipboardFormatAvailable(cfLineSelect) != 0); +	const bool isLine = SelectionEmpty() && (::IsClipboardFormatAvailable(cfLineSelect) != 0);  	ClearSelection(multiPasteMode == SC_MULTIPASTE_EACH); -	SelectionPosition selStart = sel.IsRectangular() ? -		sel.Rectangular().Start() : -		sel.Range(sel.Main()).Start();  	bool isRectangular = (::IsClipboardFormatAvailable(cfColumnSelect) != 0);  	if (!isRectangular) { @@ -1696,6 +1662,7 @@ void ScintillaWin::Paste() {  			memBorlandSelection.Unlock();  		}  	} +	const PasteShape pasteShape = isRectangular ? pasteRectangular : (isLine ? pasteLine : pasteStream);  	// Always use CF_UNICODETEXT if available  	GlobalMemory memUSelection(::GetClipboardData(CF_UNICODETEXT)); @@ -1721,7 +1688,7 @@ void ScintillaWin::Paste() {  					                      &putf[0], len + 1, NULL, NULL);  			} -			InsertPasteText(&putf[0], len, selStart, isRectangular, isLine); +			InsertPasteShape(&putf[0], len, pasteShape);  		}  		memUSelection.Unlock();  	} else { @@ -1749,9 +1716,9 @@ void ScintillaWin::Paste() {  						// CP_UTF8 not available on Windows 95, so use UTF8FromUTF16()  					UTF8FromUTF16(&uptr[0], ulen, &putf[0], mlen); -					InsertPasteText(&putf[0], mlen, selStart, isRectangular, isLine); +					InsertPasteShape(&putf[0], mlen, pasteShape);  				} else { -					InsertPasteText(ptr, len, selStart, isRectangular, isLine); +					InsertPasteShape(ptr, len, pasteShape);  				}  			}  			memSelection.Unlock(); @@ -2534,12 +2501,6 @@ STDMETHODIMP ScintillaWin::Drop(LPDATAOBJECT pIDataSource, DWORD grfKeyState,  			}  		} -		if (!data.empty() && convertPastes) { -			// Convert line endings of the drop into our local line-endings mode -			std::string convertedText = Document::TransformLineEnds(&data[0], data.size() - 1, pdoc->eolMode); -			data.assign(convertedText.c_str(), convertedText.c_str()+convertedText.length()+1); -		} -  		if (!SUCCEEDED(hr) || data.empty()) {  			//Platform::DebugPrintf("Bad data format: 0x%x\n", hres);  			return hr; | 
