TextArea not properly updating

So I am stumped, I have

function OnGUI(){
                    txtIndex = EditorGUILayout.Popup(txtIndex, temp,GUILayout.Width(100));
			if(txtIndex != 0){
				var sr : StreamReader = new StreamReader(filename);
				notepad = sr.ReadToEnd();
	    			txtIndex = 0;
			notepad = EditorGUI.TextArea(Rect(0,0,550,600),notepad, GUI.skin.customStyles[0]);

At first the TextArea is my String set as “Default”, then when I go to the popup and select a file to load it loads the file and as long as I don’t make any changes to the text area I can load other files without issue.

Now when I make a change and then switch to a file I know from other code that the file is loaded, but the textarea stays as whatever change I set it to. Now if I click off the window it changes the textarea to the file text, but when I click back on the Window the textarea changes right back to the text I had changed prior to reloading a text file. I just cant wrap my head around it, I dont want to leave the txtIndex to the file I selected as this wouldn’t allow for changes to the text if I needed.

I probably have to explain this a little further, but I am tired and been stuck on this for awhile. Thanks in advance.

While you are editing a TextArea or TextField, changes to the source string will not be picked up by the text editor. You could try removing Focus from the TextArea when you want to change the text by calling:

GUIUtility.keyboardControl = 0;
GUIUtility.hotControl = 0;